-
Notifications
You must be signed in to change notification settings - Fork 0
63. Unique Paths Ⅱ #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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.
hayashi-ay
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
良いと思います。
63. Unique Paths Ⅱ
Outdated
There was a problem hiding this comment.
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で表されるとしたらこの処理だと書き直さないといけなくなってしまいます。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
今後obstacleでもemptyでもない種類が追加されたりするケース
あーこれは全然考えられてなかったです。
今まであんまりこういうことは考えられてなかったですね。ありがとうございます。
63. Unique Paths Ⅱ
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
個人的にはcolでも十分伝わるかなと思います。
63. Unique Paths Ⅱ
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
三項演算子は横に長くなって見づらいと個人的には思います。Step2の最後のコードが個人的には好みです。
63. Unique Paths Ⅱ
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ある行の値を計算するためには、一つ上の行の値だけ分かっていたら良いですね。
63. Unique Paths Ⅱ
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
個人的にですが、(0, 0)の位置の処理はループの外で行う方が好みだなと思いました。
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.