얼렁뚱땅 스며드는 Data Science

Algorithm/Daily Coding Tests Challenge

[Leetcode] Easy: Valid Anagram

Jesip14 2021. 9. 15. 19:57

Description

Given two strings s and t, return true if t is an anagram of s, and false otherwise.

 

My solution

class Solution:
    def isAnagram(self, s: str, t: str) -> bool:
        new_t = t
        for i in s:
            t= t.replace(i, "", 1)
        
        for j in new_t:
            s = s.replace(j, "", 1)
        
        return True if (t == "") and (s == "") else False
class Solution:
    def isAnagram(self, s: str, t: str) -> bool:
        return sorted(list(s)) == sorted(list(t))

 

문제 출처 : https://leetcode.com/problems/valid-anagram/submissions/