Skip to content

Commit d53776c

Browse files
committed
leetcode(122). Best Time to Buy and Sell Stock II
1 parent e54fa8d commit d53776c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

problem56/main.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
//122. Best Time to Buy and Sell Stock II
3+
int maxProfit(List<int> prices) {
4+
int profit=0;
5+
6+
for(int i=1;i<prices.length;i++){
7+
if(prices[i-1]<prices[i]){
8+
profit+=prices[i]-prices[i-1];
9+
}
10+
}
11+
return profit;
12+
}

0 commit comments

Comments
 (0)