package leetcode;

/**
 * https://leetcode.com/problems/count-largest-group/
 */
public class Problem1399 {
    public int countLargestGroup(int n) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1399 prob = new Problem1399();
        System.out.println(prob.countLargestGroup(13)); // 4
        System.out.println(prob.countLargestGroup(14)); // 5
        System.out.println(prob.countLargestGroup(20)); // 1
        System.out.println(prob.countLargestGroup(2)); // 2
        System.out.println(prob.countLargestGroup(15)); // 6
        System.out.println(prob.countLargestGroup(24)); // 5
    }
}

@@ -12,16 +12,65 @@
 tcode;%0A%0A
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 /**%0A * h
@@ -204,314 +204,345 @@
     
-// TODO%0A        return 0
+int max = 0;%0A        Map%3CInteger, Integer%3E map = new HashMap%3C%3E()
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1399 prob = new Problem1399();%0A        System.out.println(prob.countLargestGroup(13)); // 4%0A        System.out.println(prob.countLargestGroup(14)); // 5%0A        System.out.println(prob.countLargestGroup(20)); //
+for (int i = 1; i %3C= n; i++) %7B%0A            String s = Integer.toString(i);%0A            int sum = 0;%0A            for (int j = 0; j %3C s.length(); j++) %7B%0A                sum += s.charAt(j) - '0';%0A            %7D%0A            int newCount = map.getOrDefault(sum, 0) +
  1
+;
 %0A   
@@ -550,181 +550,287 @@
     
-System.out.println(prob.countLargestGroup(2)); // 2%0A        System.out.println(prob.countLargestGroup(15)); // 6%0A        System.out.println(prob.countLargestGroup(24)); // 5
+    map.put(sum, newCount);%0A            max = Math.max(max, newCount);%0A        %7D%0A        int answer = 0;%0A        for (Map.Entry%3CInteger, Integer%3E e : map.entrySet()) %7B%0A            if (e.getValue() == max) %7B%0A                answer++;%0A            %7D%0A        %7D%0A        return answer;
 %0A   

Solve problem 1399