Share my c++ Solution


  • 2
    V
    class Solution {
    public:
        bool isAnagram(string s, string t) {
            int a[26] = {0};
            
            int i=0,j=0;
            while(s[i] && t[j]) {
                a[s[i]-'a'] += 1;
                a[t[j]-'a'] -= 1;
                i += 1;
                j += 1;
            }
            if(s[i] || t[j])
                return false;
            for(int i=0;i<26;i++)
                if(a[i])
                    return false;
            return true;
        }
    };

Log in to reply
 

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