题目

leetcode 链接:https://leetcode-cn.com/problems/valid-anagram/

image.png

解法

  1. class Solution {
  2. public boolean isAnagram(String s, String t) {
  3. if (s.length() != t.length()) {
  4. return false;
  5. }
  6. int[] tmp = new int[26];
  7. char[] str = s.toCharArray();
  8. for (char c : str) {
  9. tmp[c - 97]++;
  10. }
  11. str = t.toCharArray();
  12. for (char c : str) {
  13. if (tmp[c - 97]-- < 1) {
  14. return false;
  15. }
  16. }
  17. return true;
  18. }
  19. }