imashutosh51

Valid Anagram

Feb 27th, 2026
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. M-1
  2. class Solution:
  3.     def isAnagram(self, s: str, t: str) -> bool:
  4.         #sort the string and compare
  5.         if sorted(s)==sorted(t):
  6.             return True
  7.         else:
  8.             return False
  9.  
  10. M-2:
  11. #use the map, count each character in both string and then compare character by character
  12. from collections import Counter
  13. class Solution:
  14.     def isAnagram(self, s: str, t: str) -> bool:
  15.         print(Counter(s))
  16.         return Counter(s) == Counter(t)
  17.        
Advertisement
Add Comment
Please, Sign In to add comment