Open
Conversation
naoto-iwase
reviewed
Dec 2, 2025
naoto-iwase
left a comment
There was a problem hiding this comment.
お疲れさまです。
読みやすく、コメントから他の選択肢も見えていそうだと感じました。
特に違和感を持った場所はなかったです。
| - C++だと複雑になって読みにくいかな | ||
| - 関数型についてよくわからなかったのでGPTに聞いてみたが、変数の再代入をしないや状態が変化しない特徴があるらしい。(参照透過性) | ||
| - 状態が変化しないので共有データを変更しない→ロックが不要→並列処理に強い などの特徴がある(https://ja.wikipedia.org/wiki/%E9%96%A2%E6%95%B0%E5%9E%8B%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0) | ||
| - 関数型の考えや機能は他の言語で取り込まれている。(C++のlamda, rangesなど) |
There was a problem hiding this comment.
関数型の見方を知っておく・意識することで、手続き型で書くコードもなんか綺麗になっていく気がしています(?)
nodchip
reviewed
Dec 3, 2025
| return 0; | ||
| } | ||
|
|
||
| vector<int> prefix(prices.size()); |
There was a problem hiding this comment.
prefix だと接頭辞というニュアンスを感じます。最低価格が格納されるため、 min_prices あたりが良いと思います。
| return 0; | ||
| } | ||
|
|
||
| vector<int> prefix(prices.size()); |
There was a problem hiding this comment.
std::back_inserter を使用することで、あらかじめメモリを確保せずに書く方法もあります。
vector<int> prefix;
partial_sum(prices.begin(), prices.end(), back_inserter(prefix),
[](int acc, int x){ return min(acc, x); });ただ、今回の場合は読みやすさはあまり変わらず、あらかじめメモリを確保しておいたほうが、 push_back() 中のメモリの再確保が発生しないため、あらかじめメモリを確保してく書き方のほうが良いかもしれません。
Owner
Author
There was a problem hiding this comment.
コメントありがとうございます。
back_inserterを使用した書き方もあるんですね。
参考になります。
t9a-dev
reviewed
Dec 3, 2025
| - prices[0]を使うなら、ループはi = 1から始めた方が自然かもしれない? | ||
| - そこを変えても読みやすくなるわけでもないので、変えなくてもいいか。 | ||
|
|
||
| ## Step3 |
fuga-98
reviewed
Dec 10, 2025
| - https://github.com/nanae772/leetcode-arai60/pull/36/files | ||
| - buy_priceをmath.infから始めている人もいた。 | ||
| - prices[0]を使うなら、ループはi = 1から始めた方が自然かもしれない? | ||
| - そこを変えても読みやすくなるわけでもないので、変えなくてもいいか。 |
There was a problem hiding this comment.
Pythonでは整数に上限がないので番兵をmath.infにするものをよく見ます
c++だとINT_MAXとかでしょうか。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
今回の問題
https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
次の問題
https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/