Merge pull request #1209 from xiaofei-2020/greed06

添加(0122.买卖股票的最佳时机II.md):增加typescript版本
This commit is contained in:
程序员Carl
2022-04-29 08:22:58 +08:00
committed by GitHub

View File

@ -268,6 +268,18 @@ const maxProfit = (prices) => {
};
```
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;
};
```
C:
```c