You are viewing a single comment's thread. Return to all comments →
int anagram(string s){ vector<int> count(26,0); if(s.length()%2==0){ for(int i=0;i<s.size()/2;i++){ count[s[i]-'a']++; } for(int i=s.size()/2;i<s.size();i++){ count[s[i]-'a']--; } int sum = 0; for(int i=0;i<26;i++){ sum += abs(count[i]); } return sum/2; } else return -1; }
Seems like cookies are disabled on this browser, please enable them to open this website
Anagram
You are viewing a single comment's thread. Return to all comments →