diff --git a/Top150Interview/55JumpGame.py b/Top150Interview/55JumpGame.py index 6c83912..beb6969 100644 --- a/Top150Interview/55JumpGame.py +++ b/Top150Interview/55JumpGame.py @@ -4,31 +4,27 @@ def canJump(nums): :rtype: bool """ # Each index value is the maximum you can jump from that position - # count = 1 - # for x in nums: - # if x >= len(nums)-1: - # return True - # jump = nums[count] - # if x >= jump: - # if jump >= len(nums)-1: - # return True maxJump = 0 for x in range(len(nums)-1): maxJump += nums[x] - print(maxJump) + if nums[x] >= len(nums)-(x+1): + return True + # print(maxJump) if nums[x] == 0: + print(x+1) + print(len(nums)) + if nums[x+1] >= len(nums)-x: + return True return False - if maxJump >= len(nums)-1: - return True - else: - return False - - - # jump = nums[1] - # if jump >= len(nums)-1: - # print('Can make the jump') + return True + # if maxJump >= len(nums)-1: # return True # else: # return False -print(canJump([2,3,1,1,4])) -print(canJump([3,2,1,0,4])) \ No newline at end of file + +# print(canJump([2,3,1,1,4])) +print(canJump([3,2,1,0,4])) +# print(canJump([3,0,8,2,0,0,1])) +# print(canJump([2,0,2])) +# print(canJump([2,0,0])) +# print(canJump([1,1,2,2,0,1,1])) \ No newline at end of file