Skip to content

63. Unique Paths II#35

Open
5ky7 wants to merge 1 commit intomainfrom
63.-Unique-Paths-II
Open

63. Unique Paths II#35
5ky7 wants to merge 1 commit intomainfrom
63.-Unique-Paths-II

Conversation

@5ky7
Copy link
Copy Markdown
Owner

@5ky7 5ky7 commented Feb 25, 2026

# Step 2
過去のレビューを見て修正([Code4](#Code4)):
- 単なる数字(例えば`1`や`0`)が意味を持つ場合は,定数で置いて意味をわかりやすくする.
- [Style Guide](https://ttsuki.github.io/styleguide/cppguide.ja.html#:~:text=てください%E3%80%82-,定数,-名)に従い`kObstacle`としたが,この変数名はわかりやすいのか?大文字で`OBSTACLE`のようにした方がわかりやすい気もする.ご意見・採用しているプラクティスなどあればお待ちしております.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

一貫性があれば kObstacle でも OBSTACLE でも、可読性は大差ないと感じました。

Comment on lines +109 to +110
int m = obstacleGrid.size();
int n = obstacleGrid[0].size();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

インデックスに合わせて、ここも num_rows とか num_columns にしたほうが分かりやすそうです。

Comment on lines +119 to +122
if (obstacleGrid[row - 1][col - 1] == kObstacle) {
continue;
}
num_paths[row][col] += num_paths[row - 1][col] + num_paths[row][col - 1];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ひとつ余分に取っておくと、obstacleGrid-1 で引く必要があるっぽうで、境界での分岐をしなくて良くなるんですね。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

そうですね.
今回の問題やprefix sumなど漸化式的に表現できるときは,一つ余分に取ることでエッジケースを取り込めることがしばしばあって便利です.

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.

2 participants