JAVA_LeetCode 1399_Count Largest Group


JAVA_LeetCode 1399_Count Largest Group

JAVA_LeetCode 1399_Count Largest Group 풀이 class Solution { public int countLargestGroup(int n) { // hashMap의 getOrDefault를 이용한다. HashMap<Integer, Integer> map= new HashMap<>(); int sum = 0, num = 0, cnt = 0, max = 0, target = 0; for(int i = 1; i <= n; i++){ sum = 0; num = i; while(num > 0){ sum = sum + num % 10; num = num / 10; } map.put(sum, map.getOrDefault(sum, 0) + 1); } // hashmap에서 max값보다 큰 수를 찾았을 경우 그룹 수를 리셋하고, 같은 경우 그룹 수를 증가시킨다. for(int i : map.keySet()){ target = map.get(i); if(target >...


#JAVA #JAVA_CountLargestGroup #JAVA_LeetCode1399 #JAVA_LeetCode1399_CountLargestGroup #LeetCode1399_CountLargestGroup

원문링크 : JAVA_LeetCode 1399_Count Largest Group