Skip to content

Commit

Permalink
Create 0122 - Best Time to Buy And Sell Stock II
Browse files Browse the repository at this point in the history
  • Loading branch information
Ankush11903 authored Jan 8, 2023
1 parent f594ed8 commit 4595e8c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cpp/0122 - Best Time to Buy And Sell Stock II
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution {
public:
int maxProfit(vector<int>& prices) {
int ans=0;
for(int i=0;i<prices.size()-1;i++){
if(prices[i]<prices[i+1]){
int dif=prices[i+1]-prices[i];
ans+=dif;
}
}return ans;

}
};

0 comments on commit 4595e8c

Please sign in to comment.