Skip to content

Conversation

@nittoco
Copy link
Owner

@nittoco nittoco commented Jan 13, 2025

URL: https://leetcode.com/problems/generate-parentheses/description/

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.

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())
Copy link

Choose a reason for hiding this comment

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

kargs.items() 順序が入れ替わる可能性があるが、その場合でも本来同じものなのではないでしょうか。

Copy link
Owner Author

Choose a reason for hiding this comment

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

そうでした


### Step3

- かっこ列について、やはり再帰の直前、直後でpopやappendしたり、nonlocalで管理するよりは、引数で管理するのがわかりやすい
Copy link

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かどうかとわからなくなりそう

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):
Copy link

@Yoshiki-Iwasa Yoshiki-Iwasa Jan 18, 2025

Choose a reason for hiding this comment

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

unclosed_left_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.

確かに修飾語は前にあったほうがわかりやすいですね

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.

4 participants