添加(0122.买卖股票的最佳时机II.md):增加typescript版本

This commit is contained in:
Steve2020
2022-04-06 22:46:46 +08:00
parent 5c3ab04b6e
commit 92c6b3609f

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