mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
Update 0242.有效的字母异位词.md
删除一行不必要的print,简化for循环代码
This commit is contained in:
@ -123,12 +123,11 @@ Python:
|
|||||||
class Solution:
|
class Solution:
|
||||||
def isAnagram(self, s: str, t: str) -> bool:
|
def isAnagram(self, s: str, t: str) -> bool:
|
||||||
record = [0] * 26
|
record = [0] * 26
|
||||||
for i in range(len(s)):
|
for i in s:
|
||||||
#并不需要记住字符a的ASCII,只要求出一个相对数值就可以了
|
#并不需要记住字符a的ASCII,只要求出一个相对数值就可以了
|
||||||
record[ord(s[i]) - ord("a")] += 1
|
record[ord(i) - ord("a")] += 1
|
||||||
print(record)
|
for i in t:
|
||||||
for i in range(len(t)):
|
record[ord(i) - ord("a")] -= 1
|
||||||
record[ord(t[i]) - ord("a")] -= 1
|
|
||||||
for i in range(26):
|
for i in range(26):
|
||||||
if record[i] != 0:
|
if record[i] != 0:
|
||||||
#record数组如果有的元素不为零0,说明字符串s和t 一定是谁多了字符或者谁少了字符。
|
#record数组如果有的元素不为零0,说明字符串s和t 一定是谁多了字符或者谁少了字符。
|
||||||
|
Reference in New Issue
Block a user