Merge pull request #1209 from xiaofei-2020/greed06
添加(0122.买卖股票的最佳时机II.md):增加typescript版本
This commit is contained in:
commit
a325a2f437
|
|
@ -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:
|
||||||
|
|
||||||
```c
|
```c
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue