Untitled
unknown
plain_text
2 years ago
603 B
9
Indexable
class Solution {
public:
int solve(vector<int>&pri,int i,int pro,bool own){
if(i==pri.size()) {
return pro;
}
if (own){
int h=solve(pri,i+1,pro,true);
int s=solve(pri,i+1,pro + pri[i],false);
return max(h,s);
}
else{
int h=solve(pri,i+1,pro,false);
int b=solve(pri,i+1,pro-pri[i],true);
return max(h,b);
}
}
int maxProfit(vector<int>& prices) {
int pro=0;
int res=solve(prices,0,pro,false);
return res;
}
};Editor is loading...
Leave a Comment