Open
Conversation
huyfififi
reviewed
Mar 15, 2026
huyfififi
left a comment
There was a problem hiding this comment.
読みやすかったです! step 1 に挙げられている解法は、私は思いつかなかったのですが、読んでいて納得感がありました。
私だったらですが、メモリ使用量が許容範囲内であれば、2 次元配列DPの方が1次元配列DPよりもわかりやすいと思うので、2次元配列を持って読みやすさを優先させたいような気持ちがあります。
Owner
Author
|
ありがとうございます。 |
5ky7
reviewed
Mar 24, 2026
| - 今回は m+n < 200 なので動きそう | ||
|
|
||
| ```py | ||
| class Solution: |
There was a problem hiding this comment.
自分が思いついたのは,例えばm = 5, n = 2の時には5/2, 4/1をかけていく方法だったので,階乗をDPで保持しといて計算する方法が新鮮で参考になりました.
|
|
||
| path_counts = [1] * m | ||
|
|
||
| # 空間計算量を O(m) に抑えるため、1次元配列を再利用する。 |
There was a problem hiding this comment.
今回はシンプルな問題なので1次元配列を一つ用意するのが良いと思いますが,一つ前の行と今見ている行の2つを用意して
current_path_counts[row] += previous_path_counts[row - 1]のように更新するのも手かもしれません.
空間計算量をO(m)に保ちながら,場合によっては可読性が上がるので.
Owner
Author
There was a problem hiding this comment.
ありがとうございます。
配列をコピーしながら処理していくイメージを持ちました。
今度実装してみます。勉強になりました。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
今回の問題
Unique Paths - LeetCode
使用言語
Python