-
Notifications
You must be signed in to change notification settings - Fork 0
22. Generate Parenthesis.md #43
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
URL: https://leetcode.com/problems/generate-parentheses/description/ Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
| kargs_mark = (object(),) | ||
|
|
||
| def copy_generator_for_cache_and_return(*args, **kargs): | ||
| key = args + kargs_mark + tuple(kargs.items()) |
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.
kargs.items() 順序が入れ替わる可能性があるが、その場合でも本来同じものなのではないでしょうか。
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.
そうでした
|
|
||
| ### Step3 | ||
|
|
||
| - かっこ列について、やはり再帰の直前、直後でpopやappendしたり、nonlocalで管理するよりは、引数で管理するのがわかりやすい |
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.
Generator 楽しいですが、オーソドックスにこれが一番でしょうね。
Generator のいいところとして、すべて使わないときに計算を省略できるとか中間のメモリーが軽くなることがあるなどはあるでしょう。
|
|
||
| https://github.com/fhiyo/leetcode/pull/53/files | ||
|
|
||
| - (, )は英語でleft, rightともいうのか。ただ、left, right1単語だけだと、今見てるindexよりleftかどうかとわからなくなりそう |
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.
自分はopen closeを使いました
| def generateParenthesis(self, n: int) -> List[str]: | ||
| parenthesis = "" | ||
|
|
||
| def generate_parentheses_helper(left_count_unclosed, rest_right_count): |
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.
unclosed_left_countのほうが意味がわかると思います
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.
確かに修飾語は前にあったほうがわかりやすいですね
URL: https://leetcode.com/problems/generate-parentheses/description/
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.