Skip to content

Conversation

@Fuminiton
Copy link
Owner

if amount is None:
return -1

@lru_cache
Copy link

Choose a reason for hiding this comment

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

これ、サイズいくつになってますか? (意図して書いたか確認したいという意図です。)
cache でもいいかもしれませんね。

特に問題ないかと思います。

Copy link
Owner Author

Choose a reason for hiding this comment

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

これ、サイズいくつになってますか? (意図して書いたか確認したいという意図です。)

指定していないので128になっていますね。サイズに制限をかけようという意図でlru_cacheを選びました。
が、よくよく考えるとamount分のサイズを確保しないといけないですし、サイズもそこまで大きくないのでcacheにするべきですね。

@functools.lru_cache(maxsize=128, typed=False)

https://docs.python.org/ja/3.13/library/functools.html#functools.lru_cache

amount、numsが空の時、作れない時は-1を返す。

amount * len(coins) が時間計算量だが、10^4 * 12 ~ 10^5程度なので、現状は問題ない。
実際、このプログラムが使われるのは自動販売機のようなお釣りを出すシステムだと思うので、amountが10^6であったり、coinの種類が1000個になったりすることは考えにくいので、一旦、この実装で良いと思う。
Copy link
Owner Author

Choose a reason for hiding this comment

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

よくよく考えたら、コンビニのセルフレジシステムでも使える。が、円ならお釣りになるのは10^4未満のはずなのでほぼ問題の制約と一致している。

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