Skip to content

Commit 9747749

Browse files
committed
solution: 0055. Jump Game
1 parent 2c8deb9 commit 9747749

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/0055/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ describe('0055. Jump Game', () => {
2121
},
2222
];
2323

24-
test.each(testCases)('Case %#', ({ input: { prices }, output }) => {
25-
const result = canJump(prices);
24+
test.each(testCases)('Case %#', ({ input: { nums }, output }) => {
25+
const result = canJump(nums);
2626
expect(result).toBe(output);
2727
});
2828
});

src/0055/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1-
function canJump(nums: number[]): boolean {}
1+
function canJump(nums: number[]): boolean {
2+
let maximumJump = nums[0];
3+
for (let i = 1; i < nums.length; i++) {
4+
if (maximumJump === 0) {
5+
return false;
6+
}
7+
maximumJump = Math.max(maximumJump - 1, nums[i]);
8+
}
9+
return true;
10+
}
211

312
export { canJump };

0 commit comments

Comments
 (0)