Algorithm118 [Algorithm / Programmers] 햄버거 만들기 [Version] ⦁ 2024.04.02 / [Algorithm / Programmers] 햄버거 만들기 import java.util.*; class Solution { public int solution(int[] ingredient) { List list = new ArrayList(); int answer = 0; for(int i : ingredient) { list.add(i); if(list.size() >= 4) { int size = list.size(); if(list.get(size - 1) == 1 && list.get(size - 2) == 3 && list.get(size - 3) == 2 && list.get(size - 4) == 1) { answer++; list.remov.. 2024. 4. 2. [Algorithm / Programmers] [PCCE 기출문제] 9번 / 이웃한 칸 [Version] ⦁ 2024.04.02 / [Algorithm / Programmers] [PCCE 기출문제] 9번 / 이웃한 칸 class Solution { public static int[] dx = {1, 0, -1, 0}; public static int[] dy = {0, 1, 0, -1}; public int solution(String[][] board, int h, int w) { String color = board[h][w]; int n = board.length; int m = board[0].length; int answer = 0; for(int i = 0; i = 0 &&.. 2024. 4. 2. [Algorithm / Programmers] 대충 만든 자판 [Version] ⦁ 2024.04.02 / [Algorithm / Programmers] 대충 만든 자판 import java.util.*; class Solution { public int[] solution(String[] keymap, String[] targets) { Map map = new HashMap(); for(int i = 0; i < keymap.length; i++) { String[] input = keymap[i].split(""); for(int j = 0; j < input.length; j++) { if(!map.containsKey(input[j])) { map.put(input[j], j + 1); }else { int order = map.get(input[j]); .. 2024. 4. 2. [Algorithm / Programmers] 숫자 짝꿍 [Version] ⦁ 2024.04.02 / [Algorithm / Programmers] 숫자 짝꿍 import java.util.*; class Solution { public String solution(String X, String Y) { Map xMap = new HashMap(); Map yMap = new HashMap(); String[] xInput = X.split(""); for(int i = 0; i < xInput.length; i++) { xMap.put(xInput[i], xMap.getOrDefault(xInput[i], 0) + 1); } String[] yInput = Y.split(""); for(int i = 0; i < yInput.length; i++) { yMa.. 2024. 4. 2. [Algorithm / Programmers] 콜라 문제 [Version] ⦁ 2024.04.01 / [Algorithm / Programmers] 콜라 문제 class Solution { public int solution(int a, int b, int n) { int takeCoke = a; int receivedCoke = 0; int remainCoke = n; int answer = 0; while (remainCoke >= a) { takeCoke = remainCoke / a; receivedCoke = takeCoke * b; remainCoke = receivedCoke + (remainCoke % a); answer += receivedCoke; } return answer; } } 2024. 4. 1. [Algorithm / Programmers] 푸드 파이트 대회 [Version] ⦁ 2024.04.01 / [Algorithm / Programmers] 푸드 파이트 대회 class Solution { public String solution(int[] food) { StringBuilder sb = new StringBuilder(); for (int i = 1; i < food.length; i++) { int count = food[i] / 2; for (int j = 0; j < count; j++) { sb.append(i); } } StringBuilder reversedSb = new StringBuilder(sb).reverse(); sb.append("0").append(reversedSb); return sb.toString(); } } 2024. 4. 1. [Algorithm / Programmers] 기사단원의 무기 [Version] ⦁ 2024.04.01 / [Algorithm / Programmers] 기사단원의 무기 class Solution { public int solution(int number, int limit, int power) { int totalScore = 0; int[] divisorCounts = new int[number + 1]; for (int i = 1; i 2024. 4. 1. [Algorithm / Programmers] 핸드폰 번호 가리기 [Version] ⦁ 2024.04.01 / [Algorithm / Programmers] 핸드폰 번호 가리기 class Solution { public String solution(String phone_number) { int length = phone_number.length(); String masked = phone_number.substring(0, length - 4).replaceAll(".", "*"); return masked + phone_number.substring(length - 4); } } 2024. 4. 1. [Algorithm / Programmers] 나누어 떨어지는 숫자 배열 [Version] ⦁ 2024.04.01 / [Algorithm / Programmers] 나누어 떨어지는 숫자 배열 import java.util.*; class Solution { public int[] solution(int[] arr, int divisor) { List list = new ArrayList(); for (int num : arr) { if (num % divisor == 0) { list.add(num); } } if (list.isEmpty()) { return new int[] {-1}; } int[] answer = list.stream().mapToInt(Integer::intValue).toArray(); Arrays.sort(answer); return answer; .. 2024. 4. 1. 이전 1 2 3 4 5 6 7 ··· 14 다음