# 242. Valid Anagram

Given two strings s and t , write a function to determine if t is an anagram of s.

Example 1:

Input: s = "anagram", t = "nagaram"
Output: true
Example 2:

Input: s = "rat", t = "car"
Output: false


Note:
You may assume the string contains only lowercase alphabets.

## Solution

### Hash Table

Runtime: 32 ms, faster than 41.57% of C++ online submissions for Valid Anagram.
Memory Usage: 7.4 MB, less than 100.00% of C++ online submissions for Valid Anagram.

class Solution {
public:
bool isAnagram(string s, string t) {
if(s.size()!=t.size()) return false;
unordered_map<char, int> map;
for(int i = 0; i < s.size(); i++){
map[s[i]-'a']++;
map[t[i]-'a']--;
}
for(auto it = map.begin(); it != map.end(); it++){
if(it->second != 0) return false;
}
return true;
}
};


05-14 3894

11-10 150

03-28 600

12-31 8

09-26 168

07-12 275

04-11 64

02-08 9

09-16 170

12-12 30

06-24 43

01-10 1304

10-07 19

12-14 46

10-31 15

10-30 23

11-02 15

12-27 3

04-14 60万+

03-13 15万+

02-19 18万+

03-01 13万+

03-04 14万+

03-06 3689

03-08 7万+

04-25 7万+

03-10 13万+

03-10 19万+

03-12 11万+

03-13 11万+

03-16 2851

03-18 1万+

03-19 8万+

03-19 4万+

03-20 1万+

03-22 5万+

03-24 3万+

03-25 3万+

05-08 5万+

03-25 9万+

03-30 4万+

03-26 3012

03-29 22万+

04-10 1948

03-29 10万+

03-30 17万+

04-17 5万+

04-01 3301

03-23 1万+

04-02 1万+

04-02 4万+

06-01 818

04-06 7万+

04-06 5011

04-09 8万+

04-09 3万+

05-17 9763

04-11 4万+

04-15 6万+

04-18 5万+

04-20 5万+

05-03 1万+

05-16 5万+

05-06 2万+

05-07 1万+

05-08 4万+

05-12 1万+

05-14 7472

05-16 2465

05-16 1万+

05-16 2万+

05-30 2685

05-18 9289

05-18 6001

05-18 4351

05-21 8987

05-21 9160

05-21 588

#### 框架灵魂——反射

©️2019 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客