Optimal answer using 2 loops
Complexity
Time complexity: O(n)

Space complexity: O(1)
Code

<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity: ***O(n)***
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: ***O(1)***
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public boolean digitCount(String num) {
        int[] count = new int[10];

        for(char c: num.toCharArray()){
            count[c - '0']++;
        }

        for(int i=0; i<num.length(); i++){
            if(count[i] != num.charAt(i) - '0'){
                return false;
            }
        }
        return true;
    }
}
```
['String', 'Java']