说明
字母异位词=字符串长度一样 && 字符串中的字母种类一样
数组+排序+字符串equal import java.util.Arrays; import java.util.Scanner;
class Solution { ??? public static void main(String[] args) { ??????? System.out.println(test("anagram","nagaram")); ??????? System.out.println(test("cat","car")); ??? }
??? private static? boolean test(String s,String t){ ??????? if(null == t || null == s){ ??????????? return? false; ??????? } ??????? char[] chars = s.toCharArray(); ??????? char[] chars1 = t.toCharArray(); ??????? Arrays.sort(chars); ??????? Arrays.sort(chars1); ??????? return new String(chars).equals(new String(chars1)); ??? }
}
|