Open
Conversation
|
自分は良いと思いました。StartWith使うとコードがスッキリしますね。 |
Fuminiton
reviewed
Jun 30, 2025
| if s.startswith(word, start): | ||
| is_breakable[start + len(word)] = True | ||
| return is_breakable[-1] | ||
| ``` |
nittoco
reviewed
Jul 10, 2025
|
|
||
| wordBreak 内で s と Trie木 をマッチングする書き方 | ||
| ```python | ||
| class TrieNode: |
There was a problem hiding this comment.
単独のnodeの部分と、trieの木の部分とでクラスを分ける方が自分の好みです。
| return is_breakable[-1] | ||
| ``` | ||
|
|
||
| TrieNode.get_match_lengths を実装したパターン。こちらの方が機能が分離されていて良いと思った。 |
| ```python | ||
| class TrieNode: | ||
| def __init__(self): | ||
| self.next = {} |
There was a problem hiding this comment.
https://docs.python.org/ja/3/library/functions.html#next
nextが組み込み関数の名前と衝突してるので、ややこしいことになるかもしれません
| node = node.next[char] | ||
| node.is_word_end = True | ||
|
|
||
| def get_match_lengths(self, s): |
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.
This Problem
139. Word Break
Next Ploblem
322. Coin Change
言語: Python