Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2426df6

Browse files
Best Time to Buy and Sell Stock II
1 parent 3e81921 commit 2426df6

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

‎122-best-time-to-buy-and-sell-stock-ii.py‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@
2424
Output: 0
2525
Explanation: In this case, no transaction is done, i.e. max profit = 0.
2626
"""
27-
class Solution(object):
28-
def maxProfit(self, prices):
29-
"""
30-
:type prices: List[int]
31-
:rtype: int
32-
"""
33-
maxProfit = 0
34-
for i in range(1,len(prices)):
35-
if prices[i-1] < prices[i]:
36-
maxProfit += prices[i] - prices[i-1]
37-
return maxProfit
27+
class Solution:
28+
def maxProfit(self, prices: List[int]) -> int:
29+
profit = 0
30+
31+
for index in range(1, len(prices)):
32+
if prices[index] > prices[index-1]:
33+
profit += prices[index] - prices[index-1]
34+
35+
return profit

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /