Skip to content

Conversation

Satorien
Copy link
Owner

- pathsを二次元で書いている
- 直感的ではあるかもしれないが、不要なものを取っておくのは少し抵抗がある
- 異常入力のエラーハンドリング
- list[list[int]]であることは関数の引数で指定しているので、[[]]になっているケースだけ処理できれば良さそう
Copy link

Choose a reason for hiding this comment

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

[[]]になっているケースだけ

どこまで考慮するかは別として、 [] みたいな空リストや [[1], [1,2]] みたいに長さが揃ってないときとかはその型だけでは弾けてないですね

def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int:
num_rows = len(obstacleGrid)
num_cols = len(obstacleGrid[0])
paths_to_row: list[int] = [1] + [0] * (num_cols-1)

Choose a reason for hiding this comment

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

Copy link
Owner Author

Choose a reason for hiding this comment

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

むしろ開けない方が良いように読めました。先に計算される部分をくっつけておくことで分かりやすくする意図なのかなと思っています

If operators with different priorities are used, consider adding whitespace around the operators with the lowest priority(ies). Use your own judgment; however, never use more than one space, and always have the same amount of whitespace on both sides of a binary operator:

# Correct:
i = i + 1
submitted += 1
x = x*2 - 1
hypot2 = x*x + y*y
c = (a+b) * (a-b)
# Wrong:
i=i+1
submitted +=1
x = x * 2 - 1
hypot2 = x * x + y * y
c = (a + b) * (a - b)

Choose a reason for hiding this comment

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

おっしゃる通りですね。pep8を誤読していました。
black というフォーマッタのルールではほぼ全ての演算子の前後にスペースを入れるようになっており、勘違いしていました。
https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-breaks-binary-operators

def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int:
num_rows = len(obstacleGrid)
num_cols = len(obstacleGrid[0])
paths_to_row: list[int] = [1] + [0] * (num_cols-1)
Copy link

@tokuhirat tokuhirat Jun 23, 2025

Choose a reason for hiding this comment

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

paths_to_row だけではどのような変数か読み取ることができませんでした。例えば col_to_num_paths はいかがでしょうか。

def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int:
num_rows = len(obstacleGrid)
num_cols = len(obstacleGrid[0])
paths_to_row = [1 if col == 0 else 0 for col in range(num_cols)]

Choose a reason for hiding this comment

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

paths_to_row = [0] * num_cols
paths_to_row[0] = 1

でよいと思いました。

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