my javascript solution


  • 0
    Z
    /**
     * @param {string} s
     * @param {string} t
     * @return {boolean}
     */
    function isAnagram(s, t) {
        if (s.length !== t.length) {
            return false;
        }
        const map = {};
        for (let i = 0; i < s.length; i++) {
            map[s[i]] == null ? map[s[i]] = 1 : map[s[i]]++;
        }
        for (let i = 0; i < s.length; i++) {
            if (!map[t[i]]-- > 0) {
                return false;
            }
        }
        return true;
    }
    

Log in to reply
 

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