Open
Conversation
sakzk
reviewed
Jun 23, 2024
| ``` | ||
|
|
||
| # 2nd・3rd | ||
| count_charとするよりcount_magazineとした方が分かりやすそうだと思い変更 |
There was a problem hiding this comment.
count_magazine だと、「辞書を数える」という述語、もしくは、count_of_magazine (辞書の数) の of が省略されたものとかなと予想してしまいそうです。
辞書の命名は、key と value の対応がわかりやすいように、<key>_to_<value> の形式で書いておられる方が多いように思います。
今回の問題だと、char_to_count とかでしょうか。
Owner
Author
There was a problem hiding this comment.
命名例わかりやすいです。
ありがとうございます。
sakzk
reviewed
Jun 23, 2024
| :type magazine: str | ||
| :rtype: bool | ||
| """ | ||
| count_char = defaultdict(int) |
There was a problem hiding this comment.
すでに確認されているかもしれませんが、defaultdict() に関連しては、
- dict() をつかって書き直せるか https://discord.com/channels/1084280443945353267/1235971495696662578/1236912204209586266
- deafultdict() を実装できるか https://discord.com/channels/1084280443945353267/1226508154833993788/1243957056034308148
の議論があります。
Owner
Author
There was a problem hiding this comment.
ありがとうございます。
1に関しては解く際に選択肢の幅として思いついておりまして、
他でもやっているので今回は省略させていただきます。
2は考えてみたことがないので、議論を読んでみようと思います。
URLまで引っ張っていただきありがとうございます。
Owner
Author
There was a problem hiding this comment.
defaultdictの実装を反映させていただきました。
NobukiFukui
reviewed
Jun 25, 2024
| ### ロジック | ||
| ①magazineの文字をカウント | ||
| ②ransomNoteの文字の数だけ上記から引き算 | ||
| ③もし既に文字のカウントから0のところを引こうとしていたら、return False、回り切ればTrue |
NobukiFukui
reviewed
Jun 25, 2024
| return False | ||
| count_magazine[char] -= 1 | ||
| return True | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://leetcode.com/problems/ransom-note/submissions/