Accepted 2 lines JavaScript solution


  • 0
    var isAnagram = function(s, t) {
        if (s == null || t == null || s.length != t.length) return false; // Null and length check
    
        // Split the strings into arrays of characters, sort them, and compare
        return JSON.stringify(s.split("").sort()) === JSON.stringify(t.split("").sort());
    };
    

Log in to reply
 

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