java:using hash maps
\nclass Solution {\n    public boolean digitCount(String num) {\n         Map<Integer,Integer> map=new HashMap<>();\n        for(int i=0;i<num.length();i++){\n 
```\nclass Solution {\n    public boolean digitCount(String num) {\n         Map<Integer,Integer> map=new HashMap<>();\n        for(int i=0;i<num.length();i++){\n            char a=num.charAt(i);\n            if(map.containsKey(Integer.parseInt(String.valueOf(a))))\n            {\n                map.put(Integer.parseInt(String.valueOf(a)),map.get(Integer.parseInt(String.valueOf(a)))+1);\n            }\n            else{\n                map.put(Integer.parseInt(String.valueOf(a)),1);\n            }\n        }\n        \n        for(int i=0;i<num.length();i++){\n            if(map.containsKey(i)) {\n                if (Integer.parseInt(String.valueOf(num.charAt(i))) != map.get(i)) {\n                    return false;\n                }\n            }\n            else{\n                if(Integer.parseInt(String.valueOf(num.charAt(i)))!=0)\n                    return false;\n            }\n        }\n        return true; \n    }\n}\n```
[]