Coding Test (221) 썸네일형 리스트형 [프로그래머스/자바] 접두사인지 확인하기 class Solution { public int solution(String my_string, String is_prefix) { for(int i=1; i [프로그래머스/자바] 가위 바위 보 class Solution { public String solution(String rsp) { char[] arr = rsp.toCharArray(); StringBuilder sb = new StringBuilder(); for(char c : arr) { if(c == '2') sb.append("0"); else if(c == '0') sb.append("5"); else sb.append("2"); } return sb.toString(); } } [프로그래머스/자바] 배열 만들기 1 class Solution { public int[] solution(int n, int k) { int[] answer = new int[n / k]; int index = 0; for(int i=k; i i % k == 0).toArray(); } } IntStream을 이용한 다른 분의 풀이 [프로그래머스/자바] 짝수는 싫어요 import java.util.List; import java.util.ArrayList; class Solution { public int[] solution(int n) { List list = new ArrayList(); for(int i=1; i [프로그래머스/자바] 홀짝에 따라 다른 값 반환하기 class Solution { public int solution(int n) { if(n % 2 == 1) return odd(n); return even(n); } private int odd(int n) { int sum = 0; for(int i=1; i [프로그래머스/자바] 배열의 유사도 class Solution { public int solution(String[] s1, String[] s2) { int answer = 0; for(int i=0; i [프로그래머스/자바] 피보나치 수 ❌ 재귀 함수를 이용한 실패 답안 ❌ class Solution { public int solution(int n) { return fibonacci(n) % 1234567; } private int fibonacci(int n) { if(n == 0) return 0; if(n == 1) return 1; return fibonacci(n - 1) + fibonacci(n - 2); } } 실행하니 테스트 케이스 7번부터 시간 초과가 떴다. n이 커지면서 int 범위를 넘어서는 값이 들어가기 때문인 것 같다. ✅ 통과된 답안 ✅ class Solution { public int solution(int n) { int a = 0; int b = 1; int sum = 0; for(int i=2; i [프로그래머스/자바] n보다 커질 때까지 더하기 class Solution { public int solution(int[] numbers, int n) { int answer = 0; for(int num : numbers) { answer += num; if(answer > n) break; } return answer; } } 이전 1 ··· 17 18 19 20 21 22 23 ··· 28 다음