JAVA | HashMap / Frequency Array | Easy ✅
Solution 1: Using HashMap:\n\nclass Solution {\n    public boolean digitCount(String num) {\n        Map<Integer, Integer> map = new HashMap<>();\n        for (
## Solution 1: Using HashMap:\n``` \nclass Solution {\n    public boolean digitCount(String num) {\n        Map<Integer, Integer> map = new HashMap<>();\n        for (char c : num.toCharArray()) {\n            int n = c - \'0\';\n            map.put(n, 1 + map.getOrDefault(n, 0));\n        }\n\n        for (int i = 0; i < num.length(); i++) {\n            int n = num.charAt(i) - \'0\';\n            if (n != map.getOrDefault(i, 0)) {\n                return false;\n            }\n        }\n\n        return true;\n    }\n}\n```\nSize will be at max $$10$$ so its very small.\n\n**Time complexity:** $$O(1)$$\n**Space complexity:** $$O(1)$$\n\n---\n## Solution 2: Using Frequency array:\n```\nclass Solution {\n    public boolean digitCount(String num) {\n        int[] freq = new int[10];\n        for (char c : num.toCharArray()) {\n            freq[c - \'0\']++;\n        }\n\n        for (int i = 0; i < num.length(); i++) {\n            int n = num.charAt(i) - \'0\';\n            if (n != freq[i]) {\n                return false;\n            }\n        }\n\n        return true;\n    }\n}\n```\n\nSize will be at max $$10$$ so its very small.\n\n**Time complexity:** $$O(1)$$\n**Space complexity:** $$O(1)$$\n
['Hash Table', 'String', 'Counting', 'Java']