본문 바로가기

자바456

[프로그래머스/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.
[프로그래머스/Java] 올바른 괄호 -Codeimport java.util.*;class Solution { boolean solution(String s) { Deque deque = new ArrayDeque(); for (String ss : s.split("")) { if (ss.equals("(")) { deque.add(ss); continue; } if (deque.isEmpty()) return false; deque.pop(); } return deque.isEmpty(); }} 2025. 2. 28.
[프로그래머스/Java] JadenCase 문자열 만들기 -Codeclass Solution { public String solution(String s) { String[] s_arr = s.toLowerCase().split(" ", -1); for (int i = 0; i 2025. 2. 28.
[프로그래머스/Java] 최솟값 만들기 -Codeimport java.util.Arrays;class Solution{ public int solution(int []A, int []B){ int answer = 0; int len = A.length; Arrays.sort(A); Arrays.sort(B); for (int i = 0; i 2025. 2. 28.
[프로그래머스/Java] 최댓값과 최솟값 -Codeimport java.util.*;import java.util.stream.Collectors;class Solution { public String solution(String s) { List list = Arrays.stream(s.split(" ")) .mapToInt(Integer::parseInt) .boxed() .collect(Collectors.toList()); return Collections.min(list) + " " + Collections.max(list); }} 2025. 2. 27.
[프로그래머스/Java] 문자열 나누기 -Codeclass Solution { public int solution(String s) { int answer = 0; int same = 0, different = 0; String now = ""; for (String el : s.split("")) { if (now.isEmpty()) { now = el; } if (now.equals(el)) same++; else different++; if (same == different) { answer++; .. 2025. 2. 27.