Skip to content

Conversation

@Fuminiton
Copy link
Owner

if len(prices) < 2:
return 0
max_profit = 0
lowest_profit_so_far = prices[0]
Copy link
Owner Author

Choose a reason for hiding this comment

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

max_profitにつられて、lowest_price_so_farと間違えてますね。

return 0
max_profit = 0
min_price_so_far = prices[0]
for price in prices[1:]:
Copy link

Choose a reason for hiding this comment

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

これスライスしなくても動きそうですね。
番兵でも書けそうです。

Copy link
Owner Author

Choose a reason for hiding this comment

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

レビューありがとうございます。

これスライスしなくても動きそうですね。

おっしゃる通りですね。

番兵でも書けそうです。

max_profit = 0として、len(nums)==1の時はそのまま0で返すのが良さそうです。

Comment on lines +67 to +68
if len(prices) < 2:
return 0
Copy link

Choose a reason for hiding this comment

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

1の場合のみであるという意図は伝わりにくいですね。あと、なくても動きますね。

Copy link
Owner Author

Choose a reason for hiding this comment

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

レビューありがとうございます。

1の場合のみであるという意図は伝わりにくいですね。

おっしゃる通り、if len(prices) == 1: の方が素直ですね。

あと、なくても動きますね。

2日以上のデータが与えられたときのことを考えて67,68を書きましたが、
step2,3をやる中で、なくてもよいことに気付くべきでした。

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