Advertisement
MuzammiL5

Anagram

Jun 27th, 2021
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. class Solution {
  2. public:
  3. bool isAnagram(string s, string t) {
  4. if (s.size() != t.size()) {
  5. return false;
  6. }
  7. int count1[26] = {0}, count2[26] = {0};
  8. for (int i=0; i<s.size(); i++) {
  9. count1[s[i]-'a']++;
  10. count2[t[i]-'a']++;
  11. }
  12. for(int i=0; i<26; i++) {
  13. if (count1[i] != count2[i])
  14. return false;
  15. }
  16. return true;
  17. }
  18. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement