添加(0122.买卖股票的最佳时机II.md):增加typescript版本
This commit is contained in:
parent
5c3ab04b6e
commit
92c6b3609f
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue