---
# System prepended metadata

title: 0242. Valid Anagram
tags: [Leetcode, Bloomberg, Easy]

---

# 0242. Valid Anagram
###### tags: `Leetcode` `Easy` `Bloomberg`
Link: https://leetcode.com/problems/valid-anagram/
## Code O(N) O(1)
```java=
class Solution {
    public boolean isAnagram(String s, String t) {
        if(s.length()!=t.length()){
            return false;
        }
        int[] cnt = new int[26];
        for(int i = 0;i < s.length();i++){
            cnt[s.charAt(i)-'a']++;
        }
        for(int i = 0;i < t.length();i++){
            cnt[t.charAt(i)-'a']--;
            if(cnt[t.charAt(i)-'a']<0){
                return false;
            }
        }
        return true;
    }
}
```
## FollowUp
用hashmap