python-algorithm

leetcode 242. Valid Anagram

무적김두칠 2023. 6. 23. 15:38

https://leetcode.com/problems/valid-anagram/description/?envType=study-plan-v2&envId=top-interview-150 

 

Valid Anagram - LeetCode

Can you solve this real interview question? Valid Anagram - 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

leetcode.com

 

1
2
3
4
5
6
7
class Solution:
    def isAnagram(self, s: str, t: str-> bool:
        answer  =False
        s, t = sorted([i for i in s]), sorted([i for i in t])
        if s == t:
            answer =True
        return answer
cs
반응형