Skip to content

Conversation

Satorien
Copy link
Owner

orders_of_move_right *= (i - m + 1)
return pos_to_move_right // orders_of_move_right
```

Copy link

Choose a reason for hiding this comment

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

for row in range(1, m):
paths_to_col[row] += paths_to_col[row-1]
return paths_to_col[-1]
```
Copy link

Choose a reason for hiding this comment

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

読みやすいです。

class Solution:
def uniquePaths(self, m: int, n: int) -> int:
paths_to_grid = [[1] * m ] * n
for i in range(1, n):

Choose a reason for hiding this comment

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

リストのコピーではなく、リストに含まれるオブジェクトへの参照をnこ作っていることは認識しておくべきだと思います。

  • If we have a mutable object (list, dict, set, etc.), we can use some specific operations to mutate it and all the variables that refer to it will see the change.
  • If we have an immutable object (str, int, tuple, etc.), all the variables that refer to it will always see the same value, but operations that transform that value into a new value always return a new object.

https://docs.python.org/3/faq/programming.html#why-did-changing-list-y-also-change-list-x

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