본문 바로가기

프로그래머스408

[프로그래머스/Java] 영어 끝말잇기 -Codeimport java.util.*;class Solution { public int[] solution(int n, String[] words) { int wrong = 0; int num = 0; int turn = 0; List wordsList = new ArrayList(); for (int i = 0; i 2025. 2. 28.
[프로그래머스/Java] 짝지어 제거하기 -Codeimport java.util.*;class Solution{ public int solution(String s) { Stack deq = new Stack(); for (String ss : s.split("")) { if (!deq.isEmpty() && deq.peek().equals(ss)) { deq.pop(); continue; } deq.add(ss); } return deq.isEmpty() ? 1: 0; }} 2025. 2. 28.
[프로그래머스/Java] 피보나치 수 -Codeimport java.util.*;class Solution { public int solution(int n) { List dp = new ArrayList(List.of(0, 1)); for (int i = 2; i 2025. 2. 28.
[프로그래머스/Java] 다음 큰 숫자 -Codeclass Solution { public int solution(int n) { int one_cnt = getOneCnt(Integer.toString(n, 2)); int num = n; while (true) { num++; int next_one_cnt = getOneCnt(Integer.toString(num, 2)); if (one_cnt == next_one_cnt) { break; } } return num; } public static int getOneCnt(String bin) { .. 2025. 2. 28.
[프로그래머스/Java] 숫자의 표현 -Codeclass Solution { public int solution(int n) { int answer = 1; for (int i = 1; i n) break; if (sum == n) { answer++; } } } return answer; }} 2025. 2. 28.
[프로그래머스/Java] 이진 변환 반복하기 -Codeclass Solution { public int[] solution(String s) { int[] answer = {0, 0}; while (s.length() > 1) { answer[0]++; answer[1] += s.replaceAll("1", "").length(); s = Integer.toBinaryString(s.replace("0", "").length()); } return answer; }} 2025. 2. 28.