12ms, C++, beats 65.57% Hash


  • 1
    H

    class Solution {
    public:
    bool isAnagram(string s, string t) {
    if(s.size() != t.size()) return false;
    int strHash[26] = {0};
    for(int i = 0; i < s.size(); i++)
    {
    strHash[s[i] - 'a']++;
    strHash[t[i] - 'a']--;
    }
    for(int i = 0; i < 26; i++)
    {
    if(strHash[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.