Skip to content

Conversation

@potrue
Copy link
Owner

@potrue potrue commented Aug 20, 2025

void combinationSumHelper(
const vector<int>& candidates,
vector<int>& combination,
int processed_until,

Choose a reason for hiding this comment

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

processed_until は candidates のインデックスなので、candidates の直後に書きたいです。また好みではありますが、start ぐらいでも伝わるかなと思いました。
元の引数が candidates なのでなんとも言えないところですが、combination も results に入るかどうかの候補なので、candidates は nums とした方が自然に読みやすいと思いました。

candidates.emplace_back(num);
while (!combination.empty() && combination.back() == num) {
combination.pop_back();
}

Choose a reason for hiding this comment

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

while (target >= 0) が回る回数を数えておき、以下のようにした方が直接理解しやすいと思いました。

        while (count) {
            combination.pop_back();
            --count;
        }

void combinationSumHelper(
const vector<int>& candidates,
vector<int>& combination,
int processed_until,

Choose a reason for hiding this comment

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

説明的ではあると思うのですが、candidates_index など、インデックスであることがわかりやすい名前のほうがよいかなと思いました。

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