-
Notifications
You must be signed in to change notification settings - Fork 0
62. Unique Paths #36
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?
62. Unique Paths #36
Conversation
|
||
public class solution1_3 { | ||
public int uniquePaths(int m, int n) { | ||
if (m < 0 || n < 0) { |
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][0] へのアクセスが大丈夫な保証がありません。
} | ||
return countOfPath[n - 1]; | ||
} | ||
} |
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.
分かりやすいです。
|
||
public class solution2_1 { | ||
public int uniquePaths(int m, int n) { | ||
if (m < 0 || n < 0) { |
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.
一応、配列の範囲外アクセスも考慮して、m=0 or n=0もここで一緒に弾いてもいいと思います。(今回はm>=1、n>=1とされていますが)
|
||
public class soluion1_2 { | ||
public int uniquePaths(int m, int n) { | ||
if (m < 0 || n < 0) { |
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にして、L20~21の条件分岐を減らすかもしれません
for (int row = 0; row < m; row++) { | ||
for (int col = 0; col < n; col++) { |
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.
rowとcolを1から回しても大丈夫そうですね
* 他の人のPR参考にしたもの | ||
* | ||
* https://github.com/irohafternoon/LeetCode/pull/36/files#r2075900092 | ||
* DPの考えは同じだが、一部更新部分を変えたもの。 |
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.
この更新方法が個人的には一番好きです
問題URL:https://leetcode.com/problems/unique-paths/description/