Skip to content

Conversation

@docto-rin
Copy link
Owner

Copy link

@eito2002 eito2002 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

問題ないと思います、Unicode対応は勉強になりました

Comment on lines +324 to +340
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
if len(s) != len(t):
return False

s_char_to_count = {}
for ch in s:
if ch not in s_char_to_count:
s_char_to_count[ch] = 0
s_char_to_count[ch] += 1

remaining_count = s_char_to_count
for ch in t:
if remaining_count.get(ch, 0) == 0:
return False
remaining_count[ch] -= 1
return True

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remaining_countとs_char_to_countは同じオブジェクトを指しているので、remaining_countは無くても良いかなと思いました

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます。

s_char_to_countがtのカウントにより減少していくのは不自然かなと思いつつ、わざわざ複製するほどでもないので同じオブジェクト参照のエイリアス変数を定義しましたが、確かに中途半端でかえって分かりにくい気がします。

おっしゃるとおりremaining_countなしの方が良いですね。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants