2377. Check if Number Has Equal Digit Count and Digit Value
My accepted JavaScript solution to LeetCode problem 2377, Check if Number Has Equal Digit Count and Digit Value, running in 0ms.
- Difficulty: Easy
- JavaScript
- Runtime 0ms
- Memory 55.5MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
JavaScript
Accepted on LeetCode — runtime 0ms, memory 55.5MB, accepted 2025-12-29.
/**
* @param {string} num
* @return {boolean}
*/
var digitCount = function(num) {
const count = new Array(10).fill(0);
for (const c of num) count[+c]++;
for (let i = 0; i < num.length; i++) {
if (count[i] !== +num[i]) return false;
}
return true;
};