[JAVA] Small Optimization 5% to 83%
\nclass Solution {\n\n    public int countFreq(int[] freq, int k){\n        int n = freq.length;\n        for(int i = 0; i < n; i++){\n            if(freq[i] !=
```\nclass Solution {\n\n    public int countFreq(int[] freq, int k){\n        int n = freq.length;\n        for(int i = 0; i < n; i++){\n            if(freq[i] != k && freq[i] != 0){\n                return 0;   \n            }\n        }\n        return 1;\n    }\n    \n    public int countCompleteSubstringsUtil(char[] word, int k, int n) {\n        int alphaSize = 26;\n        int cnt = 0;\n        for(int i = 1; i <= alphaSize; i++){\n            int len = k * i;\n            if(n < len) return cnt;\n            int[] freq = new int[alphaSize];\n            for(int j = 0; j < n; j++){\n                if(j >= len) freq[word[j-len] - \'a\']--;\n                freq[word[j] - \'a\']++;   \n                if(j >= len -1 ) cnt += countFreq(freq, k);\n            }\n            \n        }\n        return cnt;\n    }\n    \n    \n    public int countCompleteSubstrings(String word, int k) {\n        String candidate = "";\n        char[] wordArr = word.toCharArray();\n        int n = word.length();\n        int cnt = 0;\n        for(int i = 0; i < n; i++) {\n            candidate += wordArr[i];\n            if(i < n - 1 && Math.abs(wordArr[i+1] - wordArr[i]) > 2){\n                cnt += countCompleteSubstringsUtil(candidate.toCharArray(), k, n);\n                candidate = "";\n            }\n        }\n        cnt += countCompleteSubstringsUtil(candidate.toCharArray(), k, n);\n        return cnt;\n    }\n}\n```\n\n**Optimization**:\nOnly changed candidate to char array.\n```\n  public int countCompleteSubstrings(String word, int k) {\n        char[] candidate = new char[word.length()];\n        int ptr = 0;\n        char[] wordArr = word.toCharArray();\n        int n = word.length();\n        int cnt = 0;\n        for(int i = 0; i < n; i++) {\n            candidate[ptr++] = wordArr[i];\n            if(i < n - 1 && Math.abs(wordArr[i+1] - wordArr[i]) > 2){\n                cnt += countCompleteSubstringsUtil(candidate, k, ptr);\n                ptr = 0;\n            }\n        }\n        cnt += countCompleteSubstringsUtil(candidate, k, ptr);\n        return cnt;\n    }\n```
['Java']