int max(int i,int j){
if(i>j) return i;
return j;
}
int maxProfit(int* prices, int pricesSize) {
int** dp=(int**)malloc(sizeof(int*)*pricesSize);
for(int i=0;i<pricesSize;i++) dp[i]=(int*)malloc(sizeof(int)*2);
dp[0][0]=0,dp[0][1]=-prices[0];
for(int i=1;i<pricesSize;i++){
dp[i][0]=max(dp[i-1][0],dp[i-1][1]+prices[i]);
dp[i][1]=max(dp[i-1][1],dp[i-1][0]-prices[i]);
}
return dp[pricesSize-1][0];
}
标签:return,int,pricesSize,122,最佳时机,IIc
From: https://www.cnblogs.com/llllmz/p/18077202