Skip to content

122. Best Time to Buy and Sell Stock II#36

Open
hemispherium wants to merge 2 commits into
mainfrom
0122-best-time-to-buy-and-sell-stock-II
Open

122. Best Time to Buy and Sell Stock II#36
hemispherium wants to merge 2 commits into
mainfrom
0122-best-time-to-buy-and-sell-stock-II

Conversation

@hemispherium
Copy link
Copy Markdown
Owner

@hemispherium hemispherium self-assigned this Apr 28, 2026
class Solution {
public:
int maxProfit(vector<int>& prices) {
int hold = -prices[0];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

入力配列の長さをチェックすると,LeetCodeの問題が置く制約を満たさないような入力に対しても正常に動く実装になりますね.エラーを返す実装でもいいと思います.

class Solution {
public:
int maxProfit(vector<int>& prices) {
int hold = -prices[0];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

動詞の原形から始まる変数名は関数名のような印象を受けます. holdingnot_holding などはいかがでしょうか?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

了解です!ご指摘ありがとうございます。

Copy link
Copy Markdown

@arahi10 arahi10 left a comment

Choose a reason for hiding this comment

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

コメントつけました.(自分はまだこの問題でコーディング練習をしていませんが....)
よろしくお願いいたします.

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.

2 participants