Skip to content

63. Unique Paths II#33

Open
TakayaShirai wants to merge 1 commit intomainfrom
63_unique_paths_II
Open

63. Unique Paths II#33
TakayaShirai wants to merge 1 commit intomainfrom
63_unique_paths_II

Conversation

@TakayaShirai
Copy link
Copy Markdown
Owner

@TakayaShirai TakayaShirai self-assigned this Feb 27, 2026
Copy link
Copy Markdown

@5ky7 5ky7 left a comment

Choose a reason for hiding this comment

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

全体的に読みやすかったです!
動的計画でやる場合「一方通行の更新は1次元配列のみでできる」ということを見落としていたので良い気づきになりました.

Comment on lines +19 to +20
final rows = obstacleGrid.length;
final cols = obstacleGrid[0].length;
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_colsの方が好みです.

Comment on lines +68 to +69
for (var row = 0; row < rows; row++) {
for (var col = 0; col < cols; col++) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

行数 rows と、インデックスである row が字面の上で似ているので、インデックスを r にするとか、行数を num_rows にするなどして区別しやすいようにすると良いと思いました。


for (var row = 0; row < rows; row++) {
for (var col = 0; col < cols; col++) {
if (obstacleGrid[row][col] == obstacle || (row == 0 && col == 0)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

結果としては同じ (continue) になるものの、状況が違うので、if文を分けたほうが分かりやすいと感じました。

uniquePathsCount[0][0] = 1;

int uniquePaths(int row, int col) {
if (row < 0 || row >= rows || col < 0 || col >= cols) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

not (0 <= row < rows) が分かりやすいと思いました。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Dartはchained comparisonを採用していなさそうですね(cf).
not (0 <= row && row < rows)のように「『正しいケース』ではない」という自然言語の説明に近いコードの方が意図がわかりやすいという点は同感です.

@mamo3gr
Copy link
Copy Markdown

mamo3gr commented Mar 5, 2026

相変わらず読みやすかったです!

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.

3 participants