mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 15:45:40 +08:00
添加(0122.买卖股票的最佳时机II.md):增加typescript版本
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user