标签:
1. 把string变为char数组
2. 排序Arrays.sort()
public class Solution { /** * @param s: The first string * @param b: The second string * @return true or false */ public boolean anagram(String s, String t) { if(s == null || t == null) return false; if(s.length() != t.length()) return false; char[] arrs = s.toCharArray(); char[] arrt = t.toCharArray(); Arrays.sort(arrs); Arrays.sort(arrt); boolean flag = true; for(int i = 0; i < arrs.length; i++){ if(arrs[i] != arrt[i]){ flag = false; } } return flag;// write your code here } };
LintCode Two Strings Are Anagrams
标签:
原文地址:http://www.cnblogs.com/LittleAlex/p/5525612.html