Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;

}
};