Quick & easy understand c++ implement in 12ms


  • 0
    L
    class Solution {
    public:
        bool isAnagram(string s, string t) {
           if (s.size()!=t.size())
    		{
    			return false;
    		}
    		vector<int>p(256, 0);
    		for  (auto var : s)
    		{
    			p[var]++;
    		}
    		for  (auto var : t)
    		{
    			p[var]--;
    		}
    		for  (auto var : p)
    		{
    			if (var!=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.