> For the complete documentation index, see [llms.txt](https://emmaguo100.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://emmaguo100.gitbook.io/leetcode/03-30-2022-242.-valid-anagram.md).

# 03/30/2022 242. Valid Anagram

Method: if the s and t's length is not equal, return false. initiate a count array. Iterate from the start of the string, get the frequency of the character in current index of s, then decrement the frequency of the charater in current index of t. After the whole iteration, check if there is any frequency != 0.

Time O(N)

Space O(1)&#x20;

```


// Some code
class Solution {
    public boolean isAnagram(String s, String t) {
        
        if (s.length() != t.length()) return false;
        int[] letters = new int[26];
        for (int i = 0; i < s.length(); i++){
            letters[s.charAt(i) -'a']++;
            letters[t.charAt(i) - 'a']--;
        }
        
        for (int letter: letters){
            if(letter != 0) return false;
        }
        
        return true;
    }
}
```
