Using Java Arrays package API, readable and concise.

  • 1

    Using Java API to improve readibility.

    import java.util.*;
    public class Solution {
        public boolean isAnagram(String s, String t) {
            * first sort the string, and then compare if they equals each other.
            * 先对字符串进行排序,然后比较是否相等
            if(s.length() == 0 ) {
                if (t.length() == 0) return true;
                else return false;
            char[] sArr = s.toCharArray();
            char[] tArr = t.toCharArray();
            return Arrays.equals(tArr, sArr);

Log in to reply

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