Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
451 B
5
Indexable
Never
var isAnagram = function(s, t) {
    
    if(s.length !== t.length) {
        return false;
    }
    
    bucketS = {}
    bucketT = {}
    
    for(i = 0 ; i< s.length ; i++) {
        bucketS[s[i]] = 1 + (bucketS[s[i]] ? bucketS[s[i]] : 0)
        bucketT[t[i]] = 1 + (bucketT[t[i]] ? bucketT[t[i]] : 0)
    }
    for(char in bucketS) {
        if(bucketS[char] != bucketT[char]) {
            return false;
        }
    }
    
    return true;
};