5-lines simple Java code using sort, easy to understand


  • 0
    S
    public static boolean isAnagram(String s, String t) {
    		char[] sArray = s.toCharArray();
    		char[] tArray = t.toCharArray();
    		Arrays.sort(sArray);
    		Arrays.sort(tArray);
    		return Arrays.equals(sArray, tArray);
    	}

Log in to reply
 

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