본문 바로가기

Algorithm118

[Algorithm / Programmers] 멀리 뛰기 [Version] ⦁ 2024.04.04 / [Algorithm / Programmers] 멀리 뛰기 class Solution { public long solution(int n) { long[] dp = new long[n + 2]; dp[1] = 1; dp[2] = 2; for (int i = 3; i 2024. 4. 4.
[Algorithm / Programmers] 2021 KAKAO BLIND RECRUITMENT-신규 아이디 추천 [Version] ⦁ 2024.04.03 / [Algorithm / Programmers] 2021 KAKAO BLIND RECRUITMENT-신규 아이디 추천 class Solution { public String solution(String new_id) { // 1단계 new_id = new_id.toLowerCase(); // 2단계 String regex = "[^a-z0-9-_.]"; new_id = new_id.replaceAll(regex, ""); // 3단계 new_id = new_id.replaceAll("\\.{2,}", "."); // 4단계 new_id = new_id.replaceAll("^\\.|\\.$", ""); // 5단계 if (new_id.isEmpty()) { ne.. 2024. 4. 3.
[Algorithm / Programmers] 바탕화면 정리 [Version] ⦁ 2024.04.03 / [Algorithm / Programmers] 바탕화면 정리 class Solution { public int[] solution(String[] wallpaper) { int minWidth = Integer.MAX_VALUE; int minHeight = Integer.MAX_VALUE; int maxWidth = Integer.MIN_VALUE; int maxHeight = Integer.MIN_VALUE; for(int i = 0; i < wallpaper.length; i++) { String[] input = wallpaper[i].split(""); for(int j = 0; j < input.length; j++) { if(input[j].equ.. 2024. 4. 3.
[Algorithm / Programmers] 2023 KAKAO BLIND RECRUITMENT-개인정보 수집 유효기간 [Version] ⦁ 2024.04.03 / [Algorithm / Programmers] 2023 KAKAO BLIND RECRUITMENT-개인정보 수집 유효기간 import java.util.*; class Solution { public int[] solution(String today, String[] terms, String[] privacies) { List expiredPrivacies = new ArrayList(); String[] todayParts = today.split("\\."); int currentYear = Integer.parseInt(todayParts[0]); int currentMonth = Integer.parseInt(todayParts[1]); int curr.. 2024. 4. 3.
[Algorithm / Programmers] 달리기 경주 [Version] ⦁ 2024.04.03 / [Algorithm / Programmers] 달리기 경주 import java.util.*; class Solution { public String[] solution(String[] players, String[] callings) { Map playerIndices = new HashMap(); for (int i = 0; i < players.length; i++) { playerIndices.put(players[i], i); } for (String calling : callings) { int index = playerIndices.get(calling); String tempPlayer = players[index - 1]; players[ind.. 2024. 4. 3.
[Algorithm / Programmers] 숫자의 표현 [Version] ⦁ 2024.04.03 / [Algorithm / Programmers] 숫자의 표현 class Solution { public int solution(int n) { int totalCount = 0; for (int i = 1; i 2024. 4. 3.
[Algorithm / Programmers] 다음 큰 숫자 [Version] ⦁ 2024.04.03 / [Algorithm / Programmers] 다음 큰 숫자 class Solution { public int solution(int n) { int oneCount = countOnes(n); for (int i = n + 1; ; i++) { if (countOnes(i) == oneCount) { return i; } } } private int countOnes(int num) { int count = 0; String binaryString = Integer.toBinaryString(num); for (char c : binaryString.toCharArray()) { if (c == '1') { count++; } } return count; } } 2024. 4. 3.
[Algorithm / Programmers] 2019 카카오 개발자 겨울 인턴십 - 크레인 인형뽑기 게임 [Version] ⦁ 2024.04.02 / [Algorithm / Programmers] 2019 카카오 개발자 겨울 인턴십 - 크레인 인형뽑기 게임 import java.util.*; class Solution { public int solution(int[][] board, int[] moves) { // [0,0,0,0,0] // [0,0,1,0,3] // [0,2,5,0,1] // [4,2,4,4,2] // [3,5,1,3,1] int answer = 0; Stack stack = new Stack(); for(int i = 0; i < moves.length; i++) { int move = moves[i] - 1; for(int j = 0; j < board.length; j++) { if(.. 2024. 4. 2.
[Algorithm / Programmers] 2020 카카오 인턴십 키패드 누르기 [Version] ⦁ 2024.04.02 / [Algorithm / Programmers] 2020 카카오 인턴십 키패드 누르기 import java.util.*; class Solution { public String solution(int[] numbers, String hand) { // L: 1, 4, 7, * // R: 3, 6, 9, # // B: 2, 5, 8, 0 Map map = new HashMap(); map.put("1", new int[] {0, 0}); map.put("2", new int[] {0, 1}); map.put("3", new int[] {0, 2}); map.put("4", new int[] {1, 0}); map.put("5", new int[] {1, 1}); .. 2024. 4. 2.