Why does this problem "Valid Anagram" have the tag "sort"?


  • -1
    Z

    Should the "sort" tag be "string"?


  • 0
    M
    public class ValidAnagram {
        
        public boolean isAnagram(String s, String t) {
            char[] cs = s.toCharArray();
            char[] ct = t.toCharArray();
            Arrays.sort(cs);
            Arrays.sort(ct);
            return new String(cs).equals(new String(ct));
        }
    
    }
    

    You know there is a solution using sort methods, though which is not the most optimal solution.


  • 0
    Z

    I see. Thank you for pointing it out.


Log in to reply
 

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