https://leetcode.com/problems/valid-anagram/description/
解题思路:
把s的数量映射到nums[],然后减去t相应的数量
代码:
class Solution {
public boolean isAnagram(String s, String t) {
if(s == null || t == null) return false;
int[] nums = new int[26];
for(int i = 0; i < s.length(); i++){
nums[s.charAt(i) - 'a']++;
}
for(int i = 0; i < t.length(); i++){
nums[t.charAt(i) - 'a']--;
}
for(int i = 0; i < nums.length; i++){
if(nums[i] != 0)
return false;
}
return true;
}
}