Create 0022-generate-parentheses.md - #54
Open
naoto-iwase wants to merge 1 commit into
Open
Conversation
potrue
reviewed
Nov 4, 2025
| if close_remain > open_remain: | ||
| stack.append((path + [")"], open_remain, close_remain - 1)) | ||
|
|
||
| return results |
potrue
reviewed
Nov 4, 2025
|
|
||
| ### 実装5 | ||
|
|
||
| - Backtrackingをloopで実装。 |
There was a problem hiding this comment.
僕の認識が間違っていたら申し訳ないんですが、新しくpathを二つ生成して次に残しておくような感じになっていて、「後戻り」をしている感じではないので、厳密に言えばいわゆるバックトラックとは少し違うかもしれないと思いました。
potrue
reviewed
Nov 4, 2025
| path.pop() | ||
|
|
||
| dfs(0, 0) | ||
| return results |
There was a problem hiding this comment.
下のコードとは逆に、これはdfsというよりはbacktrackにあたるのではないかと思います。
ロジックは読みやすいと思います。open_used, close_usedは個数ということを分かりやすくするためにnum_open, num_closeなどでもいいかもしれないと思いました。
nodchip
reviewed
Nov 4, 2025
|
|
||
| ### 実装1 | ||
|
|
||
| - 貪欲法(枝刈りつきBFS) |
There was a problem hiding this comment.
BFS を貪欲法と呼ぶのは違和感を感じました。貪欲法は、その場その場で良さそうな選択肢を取り、最終的に最適解を得る手法だと思います。
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/generate-parentheses/
次の問題:https://leetcode.com/problems/move-zeroes/