Skip to content

Conversation

@nittoco
Copy link
Owner

@nittoco nittoco commented Jul 16, 2024

URL: https://leetcode.com/problems/unique-paths-ii/description/

You are given an m x n integer array grid. There is a robot initially located at the top-left corner (i.e., grid[0][0]). The robot tries to move to the bottom-right corner (i.e., grid[m - 1][n - 1]). The robot can only move either down or right at any point in time.

An obstacle and space are marked as 1 or 0 respectively in grid. A path that the robot takes cannot include any square that is an obstacle.

Return the number of possible unique paths that the robot can take to reach the bottom-right corner.

The testcases are generated so that the answer will be less than or equal to 2 * 109.

URL: https://leetcode.com/problems/unique-paths-ii/description/
You are given an m x n integer array grid. There is a robot initially located at the top-left corner (i.e., grid[0][0]). The robot tries to move to the bottom-right corner (i.e., grid[m - 1][n - 1]). The robot can only move either down or right at any point in time.

An obstacle and space are marked as 1 or 0 respectively in grid. A path that the robot takes cannot include any square that is an obstacle.

Return the number of possible unique paths that the robot can take to reach the bottom-right corner.

The testcases are generated so that the answer will be less than or equal to 2 * 109.
Copy link

@hayashi-ay hayashi-ay left a comment

Choose a reason for hiding this comment

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

良いと思います。

Choose a reason for hiding this comment

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

Obstacleのときの値が1なので、これでも良いのですが定数として定義してあげて、if obstacleGrid[row][column] == OBSTACLEみたいな感じで判定してあげたいです。ぱっとみで何をしているか分からないというのもありますし、拡張性も高くなると思います。
たとえば、今後obstacleでもemptyでもない種類が追加されたりするケースなどがもしありそれが2で表されるとしたらこの処理だと書き直さないといけなくなってしまいます。

Copy link
Owner Author

@nittoco nittoco Jul 16, 2024

Choose a reason for hiding this comment

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

今後obstacleでもemptyでもない種類が追加されたりするケース

あーこれは全然考えられてなかったです。
今まであんまりこういうことは考えられてなかったですね。ありがとうございます。

Choose a reason for hiding this comment

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

個人的にはcolでも十分伝わるかなと思います。

Comment on lines +101 to +103

Choose a reason for hiding this comment

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

三項演算子は横に長くなって見づらいと個人的には思います。Step2の最後のコードが個人的には好みです。

Choose a reason for hiding this comment

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

ある行の値を計算するためには、一つ上の行の値だけ分かっていたら良いですね。

Comment on lines +98 to +100
Copy link

Choose a reason for hiding this comment

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

個人的にですが、(0, 0)の位置の処理はループの外で行う方が好みだなと思いました。

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.

5 participants