diff --git a/Top150Interview/55JumpGame.py b/Top150Interview/55JumpGame.py new file mode 100644 index 0000000..6c83912 --- /dev/null +++ b/Top150Interview/55JumpGame.py @@ -0,0 +1,34 @@ +def canJump(nums): + """ + :type nums: List[int] + :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] == 0: + 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 + # else: + # return False +print(canJump([2,3,1,1,4])) +print(canJump([3,2,1,0,4])) \ No newline at end of file