Playing Hacks and Stuffs!
Given two strings s
and t
, return true if t
is an anagram of s
, and false otherwise.
An Anagram
is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
They are various ways we can solve this and one way is this:
htS
, I’ll check if htT[s] != value
if it isn’t then I return FalsehtT
is among htS
if it isn’t then I return FalseHere’s the solve script: link
Another way to easily solve this is to first sort both strings then check if they are the same or not
Since for it to be anagram each they basically need to be the same after arranging the letters if scattered
Here’s the script:
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
if sorted(s) != sorted(t):
return False
return True