Posted on 2023-12-16 18:28
Uriel 閱讀(29)
評論(0) 編輯 收藏 引用 所屬分類:
閑來無事重切Leet Code 、
Hash
求問兩個字符串是否由完全相同的字母不同的組合而成,用python的count判斷每個字出現次數
#242
#Runtime: 20 ms (Beats 96.2%)
#Memory: 13.7 MB (Beats 69.85%)
class Solution(object):
def isAnagram(self, s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""
if len(s) != len(t):
return False
for i in set(s):
if s.count(i) != t.count(i):
return False
return True