赞
踩
我不知道将去向何方,但我已在路上! |
---|
时光匆匆,虽未曾谋面,却相遇于斯,实在是莫大的缘分,感谢您的到访 ! |
示例 1 :
输入: s = "anagram", t = "nagaram"
输出: true
示例 2 :
输入: s = "rat", t = "car"
输出: false
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
if len(s) != len(t):
return False
for i in range(len(s)):
if s.count(s[i]) != t.count(s[i]):
return False
return True
# 执行用时 :5384 ms, 在所有 Python3 提交中击败了5.06%的用户
# 内存消耗 :13.6 MB, 在所有 Python3 提交中击败了29.92%的用户
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
a, b = list(s), list(t)
a.sort(), b.sort()
if a != b:
return False
return True
# 执行用时 :60 ms, 在所有 Python3 提交中击败了68.13%的用户
# 内存消耗 :14.6 MB, 在所有 Python3 提交中击败了8.33%的用户
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。