JAVA | Simple Solution | HashMap & Counting | 100% Faster
Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n\n# Co
# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n\n    public boolean digitCount(String num) {\n        Map<Integer, Integer> occurrence = new HashMap<>(num.length());\n        for (int i = 0; i < num.length(); i++) {\n            int currentDigit = num.charAt(i) - \'0\';\n            occurrence.put(currentDigit, occurrence.getOrDefault(currentDigit, 0) + 1);\n        }\n\n        for (int i = 0; i < num.length(); i++) {\n            int currentDigit = num.charAt(i) - \'0\';\n            int count = 0;\n            if (occurrence.containsKey(i)) {\n                count = occurrence.get(i);\n            }\n            if (count != currentDigit) {\n                return false;\n            }\n        }\n\n        return true;\n    }\n}\n```
['Hash Table', 'String', 'Counting', 'Java']