Skip to content

63. Unique Paths II #37

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 2 commits into
base: main
Choose a base branch
from
Open

63. Unique Paths II #37

wants to merge 2 commits into from

Conversation

ryoooooory
Copy link
Owner

* ガイドをみてもループないならOKそう
* 入力配列のバリデーションもやはり意識すべし
* エッジ初期化を先にする手法。コード量は増えるがやってることは少し、明示的な気もするなくらいな気持ち。
*
Copy link

Choose a reason for hiding this comment

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

いいんじゃないでしょうか。1次元でやっている人も見ましたね。

numOfPaths[r][c] = 0;
continue;
}
if (r != 0) {
Copy link

Choose a reason for hiding this comment

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

ループが r=1 から始まっているので不要だと思います。
反対に、この条件を入れるならr, cが0の場合を処理しているループを二重ループの方に統合できますね。r, cが両方0の場合の処理も入れる必要がありますが

if (numOfCol == 0) {
return 0;
}
if (obstacleGrid[0][0] == OBSTACLE || obstacleGrid[numOfRow - 1][numOfCol - 1] == OBSTACLE) {
Copy link

Choose a reason for hiding this comment

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

自分も無駄な計算が生じないようにこうやって弾きたくなります。
01
11
から始まるような場合もグリッドが大きいと最適化したくなるかもしれませんね。

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