leetcode 有效的字母異位詞 python3

class Solution:
    def isAnagram(self, s: str, t: str) -> bool:
        temp1 = {}
        temp2 = {}
        for i in s:
            temp1[i] = s.count(i)
        for j in t:
            temp2[j] = t.count(j)
        return (temp1 == temp2)

方案二:
class Solution:
    def isAnagram(self, s: str, t: str) -> bool:
        return sorted(s) == sorted(t)

轉載自:https://blog.csdn.net/isabloomingtree/article/details/106420670

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章