Skip to content

Commit 44c5fb3

Browse files
committed
add python solution for problem 55
1 parent 54965bc commit 44c5fb3

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ LeetCode
360360
|58|[Length of Last Word](https://leetcode.com/problems/length-of-last-word/)| [C++](./algorithms/cpp/lengthOfLastWord/lengthOfLastWord.cpp), [Java](./algorithms/java/src/lengthOfLastWord/LengthOfLastWord.java)|Easy|
361361
|57|[Insert Interval](https://leetcode.com/problems/insert-interval/)| [C++](./algorithms/cpp/insertInterval/insertInterval.cpp)|Hard|
362362
|56|[Merge Intervals](https://leetcode.com/problems/merge-intervals/)| [C++](./algorithms/cpp/mergeIntervals/mergeIntervals.cpp)|Hard|
363-
|55|[Jump Game](https://leetcode.com/problems/jump-game/)| [C++](./algorithms/cpp/jumpGame/jumpGame.cpp)|Medium|
363+
|55|[Jump Game](https://leetcode.com/problems/jump-game/)| [C++](./algorithms/cpp/jumpGame/jumpGame.cpp), [Python](./algorithms/python/jumpGame/jumpGame.py)|Medium|
364364
|54|[Spiral Matrix](https://leetcode.com/problems/spiral-matrix/)| [C++](./algorithms/cpp/spiralMatrix/spiralMatrix.cpp)|Medium|
365365
|53|[Maximum Subarray](https://leetcode.com/problems/maximum-subarray/)| [C++](./algorithms/cpp/maximumSubArray/maximumSubArray.cpp)|Medium|
366366
|52|[N-Queens II](https://leetcode.com/problems/n-queens-ii/)| [C++](./algorithms/cpp/nQueens/nQueuens.II.cpp)|Hard|
@@ -433,4 +433,3 @@ LeetCode
433433
|---| ----- | -------- | ---------- |
434434
|1|[Search in a big sorted array](http://www.lintcode.com/en/problem/search-in-a-big-sorted-array/)|[Java](./algorithms/java/src/searchInABigSortedArray/searchInABigSortedArray.java)|Medium|
435435
|2|[Search Range in Binary Search Tree](http://www.lintcode.com/en/problem/search-range-in-binary-search-tree/) | [Java](./algorithms/java/src/searchRangeInBinarySearchTree/searchRangeInBinarySearchTree.java)|Medium|
436-
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Source : https://leetcode.com/problems/jump-game/
2+
# Author : Sudesh Chaudhary
3+
# Date : 2020-10-01
4+
5+
# Given an array of non-negative integers, you are initially positioned at the first index of the array.
6+
7+
# Each element in the array represents your maximum jump length at that position.
8+
9+
# Determine if you are able to reach the last index.
10+
11+
# For example:
12+
# A = [2,3,1,1,4], return true.
13+
14+
# A = [3,2,1,0,4], return false.
15+
16+
17+
# Solution
18+
# time O(n) space O(1)
19+
20+
# traverse array, maintain the most far we can go
21+
class Solution:
22+
def canJump(self, nums: List[int]) -> bool:
23+
n = len(nums)
24+
# max index where we can go
25+
farest = 0;
26+
for i in range(n):
27+
if i > farest:
28+
return False
29+
farest = max(farest, i + nums[i])
30+
return True

0 commit comments

Comments
 (0)