LeetCode solutions

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

Read the problem on LeetCode View on GitHub

JavaScript

Accepted on LeetCode — runtime 0ms, memory 55.5MB, accepted 2025-12-29.

javascript
/**
* @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;
};

Source