Skip to content

Conversation

@Fuminiton
Copy link
Owner

if len(prices) == 1:
return 0
profit = 0
yesterday_price = prices[0]
Copy link

Choose a reason for hiding this comment

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

どっちでも良いですが、prev_priceのほうが好みです。

if len(prices) == 1:
return 0
profit = 0
prev_price = prices[0]
Copy link

Choose a reason for hiding this comment

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

prev_price を定義せず

for day in range(len(prices) - 1):
    profit += max(0, prices[day + 1] - prices[day])

で回してもよいと思いました。

Copy link
Owner Author

Choose a reason for hiding this comment

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

レビューありがとうございます。
dayでループすると、前日と当日を比べていることが直感的に理解できてとても良いですね。

Comment on lines +82 to +83
if len(prices) == 1:
return 0
Copy link

Choose a reason for hiding this comment

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

あってもいいですが、これはなくてもいいですね。

for i in range(1, len(prices)):
if prices[i] >= prices[i - 1]:
continue
profit += max(0, prices[i - 1] - buy_price)

Choose a reason for hiding this comment

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

このロジックだと、prices[i - 1] - buy_priceが負になることはなさそうなので、maxとの比較はいらないかもと思いました

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.

6 participants