Skip to content

63. Unique Paths II #35

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

63. Unique Paths II #35

wants to merge 1 commit into from

Conversation

fhiyo
Copy link
Owner

@fhiyo fhiyo commented Jul 6, 2024

Comment on lines +30 to +31
if obstacleGrid[0][col] == 0:
paths[col] += paths[col - 1]
Copy link

@goto-untrapped goto-untrapped Jul 6, 2024

Choose a reason for hiding this comment

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

1 の後に 0 が続いた時も値が変わらない計算をしてしまうので、else break を入れるといいのかなと思いました。
また 1 の時に break すると、より分かりやすいように思いました。(OBSTACLE があったらもう0通りだね、ですとか、まだ定数を使っていないため、33行目のif文などと合わせて読むことを考えると、な気がしました。)

Copy link
Owner Author

Choose a reason for hiding this comment

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

        for col in range(1, num_cols):
            if obstacleGrid[0][col] == 1:
                break
            paths[col] += paths[col - 1]

ありがとうございます。こういうことですよね?こちらの方が読みやすいですね。

Choose a reason for hiding this comment

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

ありがとうございます。
はい、そのイメージです。

Comment on lines +103 to +104
if row == 0 and col == 0:
continue

Choose a reason for hiding this comment

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

97行目の初期化と100から102行目のif文で十分伝わるのかなと感じたのですが、num_paths があるため、+直接 num_paths_table[row][col] に代入して というふうにもできるのかなと思いました。

if obstacleGrid[row][col] == Solution.OBSTACLE:
num_paths_row[col] = 0
continue
if col == 0:

Choose a reason for hiding this comment

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

if col == 0: はインデックスエラーにならないためだけにあると思ったので、中に += を入れられるようにすると分かりやすくなる気がしました。好みな気がします。

Copy link
Owner Author

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.

if col != 0:
    num_paths_row[col] += num_paths_row[col - 1]

すみません、自分の言い方が微妙でした。。

Copy link
Owner Author

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.

2 participants