
파이썬 풀이 def solution(num_list): answer = [] cnt=0;cnt1=0 for i in num_list: if i%2==0: cnt=cnt+1 else: cnt1=cnt1+1 answer=[cnt,cnt1] return answer 자바 풀이 class Solution { public int[] solution(int[] num_list) { int[] answer = new int[2]; int cnt = 0; int cnt1 = 0; for (int i=0; i< num_list.length; i++){ if((num_list[i]%2)==0){ cnt++; } else{ cnt1++; } } answer[0] = cnt; answer[1] = cnt1; return an..

파이썬 풀이 def solution(price): answer = 0 if price >=500000: answer=int(price*0.8) elif price>=300000: answer=int(price*0.9) elif price>=100000: answer = int(price*0.95) else: answer = price return answer 자바 풀이 class Solution { public int solution(int price) { double answer = 0; if(price >= 500000){ answer=price*0.8; } else if(price >= 300000){ answer=price*0.9; } else if(price >= 100000){ answer =..

파이썬 풀이 def solution(str1, str2): answer = str1.find(str2) if answer == (-1): return 2 else: return 1 find 함수 string.find(찾을 문자) string.find(찾을 문자, 시작 index) string.find(찾을 문자, 시작 index, 종료 index) find 메소드는 "찾을 문자" 혹은 "찾을 문자열" 이 존재하는지 확인하여 찾는 문자가 존재한다면 해당 위치의 index 를 반환해주고 존재하지 않는다면 -1을 반환한다. 찾는 문자나 문자열이 여러개라면 맨 처음 찾은 문자의 index 를 반환하게 된다. 자바 풀이 class Solution { public int solution(String str1, St..

파이썬 풀이 def solution(strlist): answer = [] for i in strlist: answer.append(len(i)) return answer strlist 값을 for문에 넣어주었다. answer에 len(i) 값을 append 하면 간단하게 완성된다. 자바 풀이 class Solution { public int[] solution(String[] strlist) { int[] answer = new int [strlist.length]; int length = strlist.length; for (int i=0; i

파이썬 풀이 def solution(my_string): return my_string[::-1] 처음에 for문에 반복문을 돌릴까 고민했었는데, 슬라이싱을 사용할 수 있을까 라는 생각이 들었다. 문자열명[시작:종료:스텝] 음수 인덱스를 사용해서 문자열 끝에서부터 시작하여 하나씩 잘라서 리턴해주었다. 시작 - 슬라이싱을 시작할 인덱스 - 생략할 경우 '변수명[ : 종료]' 또는 '변수명[ : 종료 : 스텝]' 형태가 됨 - 생략할 경우 처음부터 슬라이싱 종료 - 슬라이싱을 종료할 인덱스 - 종료 인덱스에 있는 인덱스 전까지만 슬라이싱 - 생략할 경우 '변수명[시작 : ]' 또는 '변수명[시작 : : 스텝]' 형태가됨 - 생략할 경우 마지막 까지 슬라이싱 스텝 -몇 개씩 끊어서 슬라이싱을 할지 결정하는 값..