Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

62. Unique Paths #36

wants to merge 1 commit into from

Conversation

ryoooooory
Copy link
Owner


public class solution1_3 {
public int uniquePaths(int m, int n) {
if (m < 0 || n < 0) {
Copy link

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];
}
}
Copy link

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) {

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) {
Copy link

Choose a reason for hiding this comment

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

自分ならここで<=0にして、L20~21の条件分岐を減らすかもしれません

Comment on lines +15 to +16
for (int row = 0; row < m; row++) {
for (int col = 0; col < n; col++) {
Copy link

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の考えは同じだが、一部更新部分を変えたもの。
Copy link

Choose a reason for hiding this comment

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

この更新方法が個人的には一番好きです

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