➜ ~

Playing Hacks and Stuffs!


Project maintained by h4ckyou Hosted on GitHub Pages — Theme by mattgraham

Valid Anagram

image

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:

Here’s the solve script: link image

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

image