Code IT/Algorithm82 [프로그래머스] 위장 - Hash (Java) import java.util.*; class Solution { public static int solution(String[][] clothes) { int answer = 1; HashMap hm = new HashMap(); for (int i = 0; i < clothes.length; i++) { int sum = 1; if (hm.containsKey(clothes[i][1])) { sum = hm.get(clothes[i][1]) + 1; hm.remove(clothes[i][1]); } hm.put(clothes[i][1], sum); } for (int value : hm.values()) answer *= (value + 1); return answer - 1; } } 2021. 4. 3. [프로그래머스] 전화번호 목록 - Hash (Java) import java.util.*; class Solution { public boolean solution(String[] phone_book) { boolean answer = true; HashMap hm = new HashMap(); for (String num : phone_book) { hm.put(num, 0); } for (String num : hm.keySet()) { for (String key : hm.keySet()) { if (!key.equals(num) && key.startsWith(num)) { answer = false; break; } } } return answer; } } 2021. 4. 3. 이전 1 ··· 18 19 20 21 다음