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_00-57-50.png
35 KB
Runtime 1 ms Beats 98.18%
Memory 40.9 MB Beats 82%

#N2283. Check if Number Has Equal Digit Count and Digit Value
problem link
#solution
class Solution {
public boolean digitCount(String num) {
Map<Integer, Integer> map = new HashMap<>();
for(char c: num.toCharArray()){
int n=c-'0';
map.put(n, map.getOrDefault(n, 0) +1);
}

for(int i=0; i<num.length(); i++){
if(!map.containsKey(i) && num.charAt(i)!='0'
|| map.containsKey(i) && map.get(i)!=num.charAt(i)-'0') return false;
}
return true;
}
}
2👍2