Skip to content

Commit f06be30

Browse files
committed
D. J.:
- Added the leetcode problem and solution for 55. Jump Game
1 parent 06841cb commit f06be30

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This repository contains awesome LeetCode problems and solutions written in Pyth
66

77
- [26 Remove Duplicates from Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/description/)
88
- [27 Remove Element](https://leetcode.com/problems/remove-element/description/)
9+
- [55 Jump Game](https://leetcode.com/problems/jump-game/description/)
910
- [80 Remove Duplicates from Sorted Array II](https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/description/)
1011
- [88 Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array/description/)
1112
- [121 Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def canJump(self, nums: List[int]) -> bool:
6+
"""
7+
You are given an integer array nums. You are initially positioned at the array's first index,
8+
and each element in the array represents your maximum jump length at that position.
9+
10+
Return true if you can reach the last index, or false otherwise.
11+
"""
12+
goal = len(nums) - 1
13+
for i in range(len(nums) - 1, -1, -1):
14+
if i + nums[i] >= goal:
15+
goal = i
16+
return True if goal == 0 else False

tests/test_55_jump_game.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from typing import List
2+
3+
import pytest
4+
5+
from awesome_python_leetcode._55_jump_game import Solution
6+
7+
8+
@pytest.mark.parametrize(
9+
argnames=["nums", "expected"],
10+
argvalues=[
11+
([2, 3, 1, 1, 4], True),
12+
([3, 2, 1, 0, 4], False),
13+
],
14+
)
15+
def test_func(nums: List[int], expected: List[int]):
16+
can_jump = Solution().canJump(nums)
17+
assert can_jump == expected

0 commit comments

Comments
 (0)