Skip to content

Commit 91ce7aa

Browse files
committed
1 parent 9b4f286 commit 91ce7aa

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+
4+
int maxProfit(vector<int>& v) {
5+
int n = v.size();
6+
int curr=0,mx=0;
7+
for(int i=0;i<n-1;i++){
8+
curr+=v[i+1]-v[i];
9+
if(curr<0) curr=0;
10+
if(curr>mx) mx = curr;
11+
} return mx;
12+
}
13+
};

0 commit comments

Comments
 (0)