본문 바로가기

Algorithm118

[Algorithm / Programmers] 타겟 넘버 [Version] ⦁ 2024.03.21 / [Algorithm / Programmers] 타겟 넘버 class Solution { public static int answer = 0; public int solution(int[] numbers, int target) { BFS(numbers, target, 0, 0); return answer; } public static void BFS(int[] numbers, int target, int index, int sum) { if(sum == target && index == numbers.length) { answer++; return; } if(index > numbers.length - 1) { return; } BFS(numbers, targe.. 2024. 3. 21.
[Algorithm / Programmers] 의상 [Version] ⦁ 2024.03.21 / [Algorithm / Programmers] 의상 import java.util.*; class Solution { public int solution(String[][] clothes) { Map map = new HashMap(); for(int i = 0; i < clothes.length; i++) { String type = clothes[i][1]; map.put(type, map.getOrDefault(type, 0) + 1); } int sum = 1; for (Map.Entry entry : map.entrySet()) { sum *= (entry.getValue() + 1); } return sum - 1; } } 2024. 3. 21.
[Algorithm / Programmers] 전화번호 목록 [Version] ⦁ 2024.03.20 / [Algorithm / Programmers] 전화번호 목록 import java.util.*; class Solution { public boolean solution(String[] phoneBook) { Map map = new HashMap(); for (int i = 0; i < phoneBook.length; i++) { map.put(phoneBook[i], i); } for (int i = 0; i < phoneBook.length; i++) { for (int j = 0; j < phoneBook[i].length(); j++) { if (map.containsKey(phoneBook[i].substring(0, j))) { return fal.. 2024. 3. 20.
[Algorithm / Programmers] 완주하지 못한 선수 [Version] ⦁ 2024.03.20 / [Algorithm / Programmers] 완주하지 못한 선수 import java.util.*; class Solution { public String solution(String[] participant, String[] completion) { Map map = new HashMap(); for(int i = 0; i < participant.length; i++) { map.put(participant[i], map.getOrDefault(participant[i], 0) + 1); } for(int i = 0; i < completion.length; i++) { map.put(completion[i], map.get(completion[i]) -.. 2024. 3. 20.
[Algorithm / Programmers] 2021 카카오 채용연계형 인턴십 - 숫자 문자열과 영단어 [Version] ⦁ 2024.03.20 / [Algorithm / Programmers] 2021 카카오 채용연계형 인턴십 - 숫자 문자열과 영단어 import java.util.*; class Solution { public int solution(String s) { Map map = new LinkedHashMap(); map.put("zero", "0"); map.put("one", "1"); map.put("two", "2"); map.put("three", "3"); map.put("four", "4"); map.put("five", "5"); map.put("six", "6"); map.put("seven", "7"); map.put("eight", "8"); map.put("nine", .. 2024. 3. 20.
[Algorithm / Programmers] 가장 가까운 같은 글자 [Version] ⦁ 2024.03.20 / [Algorithm / Programmers] 가장 가까운 같은 글자 import java.util.*; class Solution { public int[] solution(String s) { Map map = new LinkedHashMap(); int[] answer = new int[s.length()]; char[] input = s.toCharArray(); for(int i = 0; i < input.length; i++) { if(!map.containsKey(input[i])) { answer[i] = -1; map.put(input[i], map.getOrDefault(input[i], 0)); }else { answer[i] = map.g.. 2024. 3. 20.
[Algorithm / Programmers] 2022 KAKAO TECH INTERNSHIP - 성격 유형 검사하기 [Version] ⦁ 2024.03.20 / [Algorithm / Programmers] 2022 KAKAO TECH INTERNSHIP - 성격 유형 검사하기 import java.util.*; class Solution { public String solution(String[] survey, int[] choices) { Map scores = new HashMap(); scores.put(1, 3); scores.put(2, 2); scores.put(3, 1); scores.put(4, 0); scores.put(5, 1); scores.put(6, 2); scores.put(7, 3); Map map = new HashMap(); for(int i = 0; i < survey.length; .. 2024. 3. 20.
[Algorithm / Programmers] 로그인 성공? [Version] ⦁ 2024.03.20 / [Algorithm / Programmers] 로그인 성공? import java.util.*; class Solution { public String solution(String[] id_pw, String[][] db) { String answer = ""; Map map = new HashMap(); for(int i = 0; i < db.length; i++) { String key = db[i][0]; String value = db[i][1]; map.put(key, value); } String id = id_pw[0]; String pw = id_pw[1]; if(map.containsKey(id)) { String value = map.get(.. 2024. 3. 20.
[Algorithm / Programmers] 로또의 최고순위와 최저순위 [Version] ⦁ 2024.03.20 / [Algorithm / Programmers] 로또의 최고순위와 최저순위 import java.util.*; class Solution { public int[] solution(int[] lottos, int[] win_nums) { int[] rank = {6, 6, 5, 4, 3, 2, 1}; Arrays.sort(lottos); Arrays.sort(win_nums); int default_win = 0; int zeroCount = 0; for(int i = 0; i < lottos.length; i++) { if(lottos[i] == 0) { zeroCount = zeroCount + 1; continue; } for(int j = 0; j < w.. 2024. 3. 20.