12ms C++ Solution


  • 0
    M
    class Solution {
    public:
        bool isAnagram(string s, string t) {
            int flag[26][2]={0};
            if(s.length()!=t.length())
                return false;
            for(int i=0;i<s.length();i++)
            {
                flag[s[i]-'a'][0]++;
                flag[t[i]-'a'][1]++;
            }
            for(int i=0;i<26;i++)
            {
                if(flag[i][0]!=flag[i][1])
                    return false;
            }
            return true;
        }
    };

  • 0
    H

    Does c++ string allow special characters? If yes then this answer is not valid.


  • 0
    S

    I think this is OK because it says "You may assume the string contains only lowercase alphabets."


Log in to reply
 

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