Skip to content

Commit 2fe0de1

Browse files
committed
leetcode.com 55. Jump Game
문제 링크: https://leetcode.com/problems/jump-game/
1 parent 68ab792 commit 2fe0de1

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

leetcode.com 55. Jump Game v2/main.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def canJump(self, nums: List[int]) -> bool:
6+
can_jump = nums[0]
7+
8+
for i in range(len(nums)):
9+
if i <= can_jump:
10+
can_jump = max(can_jump, i + nums[i])
11+
else:
12+
return False
13+
14+
return len(nums) -1 <= can_jump
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from unittest import TestCase
2+
from main import Solution
3+
4+
class TestSolution(TestCase):
5+
def test_can_jump(self):
6+
sln = Solution()
7+
self.assertEqual(True, sln.canJump([2,3,1,1,4]))
8+
9+
def test_can_jump(self):
10+
sln = Solution()
11+
self.assertEqual(False, sln.canJump([3,2,1,0,4]))

0 commit comments

Comments
 (0)