Skip to content

Commit 817ae41

Browse files
committed
Time: 290 ms (24.23%), Space: 41.8 MB (5.46%) - LeetHub
1 parent a000cc3 commit 817ae41

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
class Solution {
22
fun maxProfit(prices: IntArray): Int {
3-
43
var max = 0
54
for(i in 1 until prices.size){
6-
val left = prices[i-1]
7-
val right = prices[i]
8-
if(right > left) max += (right - left)
5+
val current = prices[i]
6+
val prev = prices[i-1]
7+
if(current > prev) max += (current - prev)
98
}
109
return max
11-
1210
}
1311
}

0 commit comments

Comments
 (0)