anagram solution java

Solutions on MaxInterview for anagram solution java by the best coders in the world

showing results for - "anagram solution java"
Diana
03 Oct 2020
1public boolean isAnagram(String s, String t) {
2    if (s.length() != t.length()) {
3        return false;
4    }
5    int[] counter = new int[26];
6    for (int i = 0; i < s.length(); i++) {
7        counter[s.charAt(i) - 'a']++;
8        counter[t.charAt(i) - 'a']--;
9    }
10    for (int count : counter) {
11        if (count != 0) {
12            return false;
13        }
14    }
15    return true;
16}
17