Use java.util.Arrays.Easy code,diffrent way.


  • 0
    C

    At first when I saw this problem,I considered that sort the char[] is an easy way.
    my code:

    public static boolean isAnagram(String s, String t) {
            char[] str = s.toCharArray();
            char[] ttr = t.toCharArray();
            Arrays.sort(str);
            Arrays.sort(ttr);
            return Arrays.equals(str,ttr);
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.