Leetcode in Java && Oracle
422 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2022-12-22_01-16-57.png
33.6 KB
Runtime16 msBeats61.69%
Memory41.4 MBBeats66.23%
#N1399. Count Largest Group
problem link
#solution
class Solution {
public int countLargestGroup(int n) {
Map<Integer, Integer> map = new HashMap<>();
int count=0, max=0;
int[] dp = new int[n+1];

for(int i=1; i<=n; i++){
dp[i]=dp[i/10]+i%10;
map.put(dp[i], map.getOrDefault(dp[i], 0) +1);
if(map.get(dp[i])>max){
count=0;
max=map.get(dp[i]);
}
if(map.get(dp[i])==max) count++;
}
return count;
}
}
👍2