#Leetcode# 242. Valid Anagram
https://leetcode.com/problems/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
代码:
class Solution {
public:
bool isAnagram(string s, string t) {
map<char, int> mp;
int ls = s.length(), lt = t.length();
if(ls != lt) return false;
for(int i = 0; i < ls; i ++)
mp[s[i]] ++;
for(int i = 0; i < lt; i ++)
mp[t[i]] --;
for(int i = 0; i < ls; i ++) {
if(mp[s[i]]) return false;
else continue;
}
return true;
}
};

浙公网安备 33010602011771号