Skip to content

62. Unique Paths#46

Merged
ryosuketc merged 1 commit intomainfrom
62_unique_paths
Jul 30, 2025
Merged

62. Unique Paths#46
ryosuketc merged 1 commit intomainfrom
62_unique_paths

Conversation

@ryosuketc
Copy link
Copy Markdown
Owner

Comment thread 62_unique_paths/step3.py
@@ -0,0 +1,9 @@
class Solution:
def uniquePaths(self, m: int, n: int) -> int:
rows = m
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

TORUS0818/leetcode#42 (comment)
実際には引数の変数名を変えることも考えたいですね。
あとは num_ をつけると実体ではなく個数であることが明確になる気がします。とはいえ10行以下のコードなのでrowsでも問題ないとは思います。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

参照リンク、考えを整理するのに参考になりました。ありがとうございます。
そうですね、私も実務なら引数自体を変えているのかなと思います。もちろんリンクの通りすでに使っている場所があるかは考える必要がありますが…。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

あと rows vs. num_rows は私も少し悩みました。無闇に省略しているわけではないし、おっしゃるとおり短いコードなので、短く書ける方を優先した形です。

Comment thread 62_unique_paths/step2.py
for position in range(1, width):
# 2d DP でいうと
# paths[position - 1]: 前の列, paths[position]: 前の行
paths[position] = paths[position] + paths[position - 1]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

paths[position] += paths[position - 1] もありでしょうか。

Comment thread 62_unique_paths/step1.py
for col in range(1, cols):
print(col)
paths[col] = previous_paths[col] + paths[col - 1]
previous_paths, paths = paths, [1] * cols
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

swap が必要なら(やや見にくいながら)この書き方もありですが、今回は
previous_paths = paths
paths = [1] * cols
で良いと思いました。

@ryosuketc ryosuketc added the comments reviewed Reviewe comments are examined. No major re-review of the problem is needed. label Jul 17, 2025
@ryosuketc ryosuketc merged commit a06163e into main Jul 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comments reviewed Reviewe comments are examined. No major re-review of the problem is needed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants