Skip to content

Commit

Permalink
Merge pull request youngyangyang04#1736 from Undertone0809/Undertone0…
Browse files Browse the repository at this point in the history
…809-patch-1

Update 0242.有效的字母异位词.md
  • Loading branch information
youngyangyang04 authored Nov 18, 2022
2 parents 93c99cb + 51d8be6 commit 1f8ea7b
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions problems/0242.有效的字母异位词.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,11 @@ Python:
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
record = [0] * 26
for i in range(len(s)):
for i in s:
#并不需要记住字符a的ASCII,只要求出一个相对数值就可以了
record[ord(s[i]) - ord("a")] += 1
print(record)
for i in range(len(t)):
record[ord(t[i]) - ord("a")] -= 1
record[ord(i) - ord("a")] += 1
for i in t:
record[ord(i) - ord("a")] -= 1
for i in range(26):
if record[i] != 0:
#record数组如果有的元素不为零0,说明字符串s和t 一定是谁多了字符或者谁少了字符。
Expand Down

0 comments on commit 1f8ea7b

Please sign in to comment.