Skip to content

Commit 9d5dd86

Browse files
authored
Merge pull request neetcode-gh#1953 from Ankush11903/main
Create 0122 - Best-Time-to-Buy-And-Sell-Stock-II.cpp
2 parents 343e195 + de27d94 commit 9d5dd86

File tree

1 file changed

+13
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)