[LeetCode] Valid Anagram

来源:互联网 发布:网络布线施工报价单 编辑:程序博客网 时间:2024/06/05 02:50

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

For example,
s = "anagram", t = "nagaram", return true.

s = "rat", t = "car", return false.


public class Solution {    public boolean isAnagram(String s, String t) {        if(s.length() != t.length()) return false;                int[] record = new int[26];        for(int i = 0; i < s.length(); i++){            record[s.charAt(i) - 'a']++;            record[t.charAt(i) - 'a']--;        }                for(int i = 0; i < record.length; i++){            if(record[i] != 0)  return false;        }                return true;    }}


0 0