Using a vector instead of map to reduce space complexity
Intuition\n Describe your first thoughts on how to solve this problem. \nUse a vector to keep track of all frequencies, and match it with the\nrequired frequenc
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse a vector to keep track of all frequencies, and match it with the\nrequired frequencies.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n* Define a vector to of size 10, as there can be only 10 numbers (0 - 10) - we will use the index as key and vector space as value.\n* Loop through the given string once, counting all characters frequency.\n* Loop again in the string, check if value of frequencyRequired is equal to the given frequency, if not -- return false;\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nTwo loops - O(n) + O(n) --> O(n);\nn : size of num\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nA vector of size 10 - O(10)\n\n# Code\n```\nclass Solution {\npublic:\n    bool digitCount(string num) {\n        vector<int> freq(10, 0);\n\n        for(char c : num){\n            freq[c - \'0\']++;\n        }\n\n        for(int i = 0; i < num.size(); i++){\n            // int requiredFreq = num[i] - \'0\';\n            if(num[i] - \'0\' != freq[i]){\n                return false;\n            }\n        }\n\n        return true;\n    }\n};\n```
['C++']