휴지통665 최솟값 만들기 package programmers; import java.util.Collections; import java.util.PriorityQueue; public class 최솟값만들기 { public static int solution(int[] A, int[] B) { int ans = 0; PriorityQueue a = new PriorityQueue(); PriorityQueue b = new PriorityQueue(Collections.reverseOrder()); for (int i = 0; i < A.length; i++) { a.add(A[i]); b.add(B[i]); } while (!a.isEmpty()) { ans += a.poll() * b.poll(); } return ans;.. 2022. 12. 27. JadenCase 문자열 만들기 package programmers; import java.util.StringTokenizer; public class JadenCase문자열만들기 { // 모든 단어의 첫 문자는 대문자 // 그 외에 알파벳은 소문자 public static String solution(String s) { StringTokenizer st = new StringTokenizer(s, " ", true); StringBuilder sb = new StringBuilder(); while (st.hasMoreTokens()) { String str = st.nextToken(); if (str.startsWith(" ")) { sb.append(str); continue; } if (isStartWithNumber(st.. 2022. 12. 26. 최대값과 최솟값 package programmers; public class 최대값과최솟값 { public static String solution(String s) { String[] strings = s.split(" "); int max = Integer.MIN_VALUE; int min = Integer.MAX_VALUE; for (String string : strings) { int number = Integer.parseInt(string); max = Math.max(max, number); min = Math.min(min, number); } return min + " " + max; } public static void main(String[] args) { System.out.println(solu.. 2022. 12. 25. 크기가 작은 부분 문자열 package programmers; public class 크기가작은부분문자열 { // 숫자로 이루어진 문자열 t, p // t 에서 p와 길이가 같은 부분 문자열 // 이 부분문자열이 나타내는 수가 p 가 나타내는 수보다 작거나 같은 것의 갯수 리턴 public static int solution(String t, String p) { int len = p.length(); long num = Long.parseLong(p); int answer = 0; for (int i = 0; i 2022. 12. 24. 햄버거 만들기 package programmers; import java.util.Stack; public class 햄버거만들기 { // 1,2,3,1{빵,야채,고기,빵} public static int solution(int[] ingredient) { int answer = 0; Stack s = new Stack(); for (int value : ingredient) { s.push(value); if (s.size() >= 4) { if (isHamburger(s)) { makeHamburger(s); answer++; } } } return answer; } private static void makeHamburger(Stack s) { for (int i = 0; i < 4; i++) { s.pop();.. 2022. 12. 23. 문자열 나누기 package programmers; public class 문자열나누기 { // 1. 첫 글자 x // 2. x의 갯수와, x가 아닌 다른 글자들이 나온 횟수를 세기 // 3. 처음으로 두 횟수가 같아지는 순간 멈추고, 지금까지 읽은 문자열 분리 // 4. 더이상 읽을 글자가 없으면 분리/종료 public static int solution(String s) { char x = s.charAt(0); int answer = 0; int mainCount = 1; int subCount = 0; for (int i = 1; i < s.length(); i++) { if (x == ' ') { x = s.charAt(i); continue; } if (x == s.charAt(i)) { mainCount+.. 2022. 12. 22. 이전 1 ··· 20 21 22 23 24 25 26 ··· 111 다음