Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1953 from Ankush11903/main
Browse files Browse the repository at this point in the history
Create 0122 - Best-Time-to-Buy-And-Sell-Stock-II.cpp
  • Loading branch information
caba5 authored Jan 8, 2023
2 parents 343e195 + de27d94 commit 9d5dd86
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.cpp
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 9d5dd86

Please sign in to comment.