Java Solution(8 ms)


  • 0
    P
        public boolean isAnagram(String s, String t) {
            
           if(s.length() != t.length())
                return false;
                
            if(s.isEmpty() && t.isEmpty())
                return true;
                
            return sort(s).equals(sort(t));
            
        }
        
        String sort(String str){
            char[] array = str.toCharArray();
            java.util.Arrays.sort(array);
            
            return new String(array);
        }
    }

Log in to reply
 

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