Open
Conversation
oda
reviewed
Dec 26, 2025
Comment on lines
+171
to
+172
| static constexpr char kFail = 0; | ||
| static constexpr char kSuccess = 1; |
There was a problem hiding this comment.
個人的には、0, 1 で false, true を表すのは普通なのでこの定数はなくてもいいかなと感じます。
| can_segment.front() = kSuccess; | ||
|
|
||
| for (int i = 1; i <= s_view.size(); ++i) { | ||
| for (auto word : word_dict) { |
Owner
Author
There was a problem hiding this comment.
たしかに、そうですね。
辞書内の単語の長さは最大20なのでconst参照の方がよかったですね。
|
|
||
| - https://github.com/katsukii/leetcode/pull/11/files | ||
| - Trieを使った解き方もある。 | ||
| - 実装が大変そうだったので、後でやろう。 |
There was a problem hiding this comment.
naoto-iwase
reviewed
Dec 26, 2025
naoto-iwase
left a comment
There was a problem hiding this comment.
選択肢を持って検討されていよいと思います。
すでにコメントが付いている点以外で読んでいて気になったことはありませんでした。
nodchip
reviewed
Dec 28, 2025
| class Solution { | ||
| public: | ||
| bool wordBreak(const string& s, const vector<string>& word_dict) { | ||
| vector<char> can_segment(s.size() + 1, kFalse); |
There was a problem hiding this comment.
少しお行儀が悪い感じがするのですが、
vector<char> can_segment(s.size() + 1, false);としても良いかなと思いました。
| if (i + word.size() > s.size()) { | ||
| continue; | ||
| } | ||
| if (s.substr(i, word.size()) != word) { |
There was a problem hiding this comment.
C++26 からは std::string::subview() 関数を使うことで、簡潔に書けるようです。
https://cpprefjp.github.io/reference/string/basic_string/subview.html
| if (s.substr(i, word.size()) != word) { | ||
| continue; | ||
| } | ||
| can_segment[i] = can_segment[i] || can_segment[i + word.size()]; |
There was a problem hiding this comment.
can_segment[i] |= can_segment[i + word.size()];のほうがシンプルだと思います。
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/word-break/
次の問題
https://leetcode.com/problems/coin-change/