Skip to content

Commit 3234c7e

Browse files
committedMay 10, 2024
[122] [Time Beats: 58.06%] [Memory Beats: 73.44%] - LeetPush
1 parent 33eb3a5 commit 3234c7e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
 
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function maxProfit(prices) {
2+
let maxProfit = 0
3+
let i = 0
4+
while (i < prices.length) {
5+
if (prices[i + 1] > prices[i]) {
6+
const profit = prices[i+1] - prices[i]
7+
maxProfit += profit
8+
}
9+
i++
10+
}
11+
return maxProfit
12+
};

0 commit comments

Comments
 (0)
Please sign in to comment.