Skip to content

Commit 2c8deb9

Browse files
committed
problem: 0055. Jump Game
1 parent 23641b7 commit 2c8deb9

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

src/0055/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# 0055. [Jump Game](https://leetcode.com/problems/jump-game/description/?envType=study-plan-v2&envId=top-interview-150)
2+
3+
You are given an integer array `nums`. You are initially positioned at the array's **first index**, and each element in the array represents your maximum jump length at that position.
4+
5+
Return `true` _if you can reach the last index, or_ `false` _otherwise_.
6+
7+
### **Example 1:**
8+
9+
<pre><code>
10+
<strong>Input:</strong> nums = [2,3,1,1,4]
11+
<strong>Output:</strong> true
12+
<strong>Explanation:</strong> Jump 1 step from index 0 to 1, then 3 steps to the last index.
13+
</code></pre>
14+
15+
### **Example 2:**
16+
17+
<pre><code>
18+
<strong>Input:</strong> nums = [3,2,1,0,4]
19+
<strong>Output:</strong> false
20+
<strong>Explanation:</strong> You will always arrive at index 3 no matter what. Its maximum jump length is 0, which makes it impossible to reach the last index.
21+
</code></pre>
22+
23+
### **Constraints:**
24+
25+
- <code>1 <= nums.length <= 10<sup>4</sup></code>
26+
- <code>0 <= nums[i] <= 10<sup>5</sup></code>

src/0055/index.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { canJump } from '.';
2+
3+
describe('0055. Jump Game', () => {
4+
interface TestCase {
5+
input: { nums: number[] };
6+
output: boolean;
7+
}
8+
9+
const testCases: TestCase[] = [
10+
{
11+
input: {
12+
nums: [2, 3, 1, 1, 4],
13+
},
14+
output: true,
15+
},
16+
{
17+
input: {
18+
nums: [3, 2, 1, 0, 4],
19+
},
20+
output: false,
21+
},
22+
];
23+
24+
test.each(testCases)('Case %#', ({ input: { prices }, output }) => {
25+
const result = canJump(prices);
26+
expect(result).toBe(output);
27+
});
28+
});

src/0055/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function canJump(nums: number[]): boolean {}
2+
3+
export { canJump };

0 commit comments

Comments
 (0)