Skip to content

Commit ac155d9

Browse files
committed
update: optimize DaleStudy#276 time complexity
1 parent 50af881 commit ac155d9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

jump-game/EGON.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ def canJump(self, nums: List[int]) -> bool:
77
return self.solve_dp(nums)
88

99
"""
10-
Runtime: 5585 ms (Beats 5.91%)
10+
Runtime: 3130 ms (Beats 11.42%)
1111
Time Complexity: O(n * m)
1212
- dp 배열 생성에 nums의 길이 n 만큼 조회하는데 O(n)
1313
- 생성한 dp 배열을 조회하는데 O(n)
1414
- dp[i]에서 점프하는 범위에 의해 * O(2 * m)
1515
> O(n) + O(n) * O(2 * m) ~= O(n * m)
1616
17-
Memory: 17.80 MB (Beats 46.08%)
17+
Memory: 17.80 MB (Beats 72.54%)
1818
Space Complexity: O(n)
1919
> nums의 길이에 비례하는 dp 배열 하나만 사용, O(n)
2020
"""
@@ -25,7 +25,7 @@ def solve_dp(self, nums: List[int]) -> bool:
2525
return True
2626

2727
if dp[i] is True:
28-
for jump in range(-nums[i], nums[i] + 1):
28+
for jump in range(nums[i] + 1):
2929
if 0 <= i + jump < len(dp):
3030
dp[i + jump] = True
3131

0 commit comments

Comments
 (0)