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

# CODE

```python
class Solution:
    def isAnagram(self, s: str, t: str) -> bool:
        if len(s) != len(t):
            return False
        if len(s) > len(t):
            small, big = t, s
        else:
            small, big = s, t
        chars = {}
        for c in small:
            chars[c] = 1 + chars.get(c, 0)
            
        for c in big:
            if c not in chars or chars[c] == 0:
                return False
            chars[c] -= 1
        return True
            
                
        
            
        
```
