Merge branch 'master' into master

This commit is contained in:
程序员Carl
2022-05-06 09:27:21 +08:00
committed by GitHub
67 changed files with 668 additions and 2741 deletions

View File

@@ -40,7 +40,7 @@
本题首先要清楚两点:
* 只有一只股票!
* 当前只有买股票或者股票的操作
* 当前只有买股票或者股票的操作
想获得利润至少要两天为一个交易单元。
@@ -264,7 +264,19 @@ const maxProfit = (prices) => {
dp[i][1] = Math.max(dp[i-1][1], dp[i-1][0] + prices[i]);
}
return dp[prices.length -1][0];
return dp[prices.length -1][1];
};
```
TypeScript
```typescript
function maxProfit(prices: number[]): number {
let resProfit: number = 0;
for (let i = 1, length = prices.length; i < length; i++) {
resProfit += Math.max(prices[i] - prices[i - 1], 0);
}
return resProfit;
};
```