Merge branch 'youngyangyang04:master' into master

This commit is contained in:
JackZJ
2022-04-29 08:36:43 +08:00
committed by GitHub
2 changed files with 29 additions and 0 deletions

View File

@ -154,6 +154,23 @@ var canJump = function(nums) {
};
```
### TypeScript
```typescript
function canJump(nums: number[]): boolean {
let farthestIndex: number = 0;
let cur: number = 0;
while (cur <= farthestIndex) {
farthestIndex = Math.max(farthestIndex, cur + nums[cur]);
if (farthestIndex >= nums.length - 1) return true;
cur++;
}
return false;
};
```
-----------------------
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>

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