-
Notifications
You must be signed in to change notification settings - Fork 0
Solved Arai60/78. Subsets #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| ## Step 3. Final Solution | ||
|
|
||
| - 再帰での実装を練習 | ||
| - List_A += List_Bを関数内関数で行うとエラー |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nonlocal List_A がいります。
+= は iadd が定義されていれば iadd なければ add を使って足し算と代入をするという仕組みなので参照先を変更する可能性があるので必要です。
近い話としては、このあたり。
https://docs.google.com/document/d/11HV35ADPo9QxJOpJQ24FcZvtvioli770WWdZZDaLOfg/edit?tab=t.0#heading=h.jwt99kks0w2
| for subset in all_subsets]) | ||
| if index_to_add + 1 < len(nums): | ||
| add_subsets(index_to_add + 1) | ||
| all_subsets = [[]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inner function 内で使用されている変数が、 inner function より後に定義されていると、変数の定義を探すために上下に目線が移動します。これは読み手にとってやや煩わしく感じます。 inner function の中で使用する変数は、 inner function より前に定義することをお勧めします。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
確かにそうですね、そうします
| same_size_subsets = [[]] | ||
| subsets = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
細かいですが、subsets の方が重要な変数だと思うので先に書きたい、また重要に見えるような変数名にしたい、と思いました。メソッド名とかぶっているのも気になりました。下で書かれている all_subsets はわかりやすいです。
問題文:https://leetcode.com/problems/subsets/description/