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. Note: You may assume the string contains only lowercase alphabets. Follow up: What if the inputs contain unicode characters? How would you adapt your solution to such case?
还不知道Unicode 该怎么做
只有lowercase alphabets的做法无外乎sort, hashmap, array, bitmap之类的
1 public class Solution { 2 public boolean isAnagram(String s, String t) { 3 if (s==null || t==null || s.length()!=t.length()) return false; 4 char[] ss = s.toCharArray(); 5 char[] tt = t.toCharArray(); 6 Arrays.sort(ss); 7 Arrays.sort(tt); 8 for (int i=0; i<ss.length; i++) { 9 if (ss[i] != tt[i]) return false; 10 } 11 return true; 12 } 13 }
原文:http://www.cnblogs.com/EdwardLiu/p/5060721.html