Accepted java solution, really simple


  • 3
    H
    public boolean isAnagram(String s, String t) {
        char[] sChar = s.toCharArray();
        char[] tChar = t.toCharArray();
        Arrays.sort(sChar);
        Arrays.sort(tChar);
        return Arrays.equals(sChar, tChar);
    }

  • 0
    W

    It's simple, however it's an nlog(n) solution.


  • 0
    B

    It is nlog(n) time, and o(n) space. However, you can solve it at least with o(n) time and o(1) space which is not difficult.


Log in to reply
 

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