From 262543afc51ea63c6ff18d73ae017b86a3e00f81 Mon Sep 17 00:00:00 2001 From: ImAlpha Date: Sat, 1 Jul 2023 19:39:11 -0700 Subject: [PATCH] passes 137/172 test cases --- Top150Interview/55JumpGame.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Top150Interview/55JumpGame.py 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