Skip to content

Create 322. Coin Change.md#40

Open
tokuhirat wants to merge 1 commit intomainfrom
322.-Coin-Change
Open

Create 322. Coin Change.md#40
tokuhirat wants to merge 1 commit intomainfrom
322.-Coin-Change

Conversation

@tokuhirat
Copy link
Owner

This Problem
322. Coin Change
Next Ploblem
35. Search Insert Position
言語: Python

amount_to_num_coins[new_total] = min(
amount_to_num_coins[new_total], amount_to_num_coins[total] + 1
)
if math.isinf(amount_to_num_coins[amount]):

Choose a reason for hiding this comment

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

math.isinfっていうのがあったんですね、初めて知りました 👀

- 確かに。この観点はないといけない。
- https://github.com/TORUS0818/leetcode/pull/42/files#r1904039471
- Generator を使う方法。書き方の幅としてはまだまだ全然見えてないなと感じた。
- 今回の複雑さであれば、初期値 inf でも許容する方針とした。

Choose a reason for hiding this comment

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

あとは、X枚で作れる金額を列挙していき、amountと一致したらXを返すようなBFSでも実装できますね。

if math.isinf(amount_to_num_coins[amount]):
return -1
return amount_to_num_coins[amount]
```

Choose a reason for hiding this comment

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

いいと思います。

)
if math.isinf(amount_to_num_coins[amount]):
return -1
return amount_to_num_coins[amount]
Copy link

Choose a reason for hiding this comment

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

amount_to_num_coins[-1] と書くこともできますが、自分も amount とした方が好みです。

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.

4 participants