Skip to content

322. Coin Change#51

Open
skypenguins wants to merge 1 commit into
mainfrom
leetcode/arai60/problem-322
Open

322. Coin Change#51
skypenguins wants to merge 1 commit into
mainfrom
leetcode/arai60/problem-322

Conversation

@skypenguins

Copy link
Copy Markdown
Owner

@skypenguins skypenguins self-assigned this Jul 20, 2026
@skypenguins skypenguins changed the title # 322. Coin Change 322. Coin Change Jul 20, 2026
Comment thread memo.md

for current_amount in range(1, amount + 1):
for coin in coins:
if current_amount >= coin:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ここの条件を反転し、continueでコードのネストを減らす方が読みやすいと思います。

Comment thread memo.md
```py
class Solution:
def coinChange(self, coins: List[int], amount: int) -> int:
min_num_coins = [float("inf")] * (amount + 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.

min_ という接頭辞は、しばしば minimum number of の略とされると思います。 min_coins で十分伝わると思います。

Comment thread memo.md
if amount == 0:
return 0
current_amounts = [0]
found = set()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

set より list のほうがデータ構造が単純で、処理が軽いイメージがあるため、個人的には list を使うことが多いです。

found = [False] * amount

ただ、定数倍の速度差しかありません。定数倍の速度差を気にするのであれば、 C++ 等、高速な言語で書いたほうが良いとも思います。

Comment thread memo.md
for current_amount in range(1, amount + 1):
for coin in coins:
if current_amount >= coin:
min_num_coins[current_amount] = min(min_num_coins[current_amount], min_num_coins[current_amount - coin] + 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.

, が 1 つ余分だと思いました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants