Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 237c7c3

Browse files
committed
No122
1 parent 648bced commit 237c7c3

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

leetcode/DP/No122.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public int maxProfit(int[] prices){
3+
if(prices.length == 0 || prices.length == 1){
4+
return 0;
5+
}
6+
int sum = 0;
7+
for(int i = 0;i < prices.length - 1;i++){
8+
if(prices[i+1] > prices[i]){
9+
sum += prices[i+1] - prices[i];
10+
}
11+
}
12+
return sum;
13+
}
14+
}

0 commit comments

Comments
 (0)