Skip to content

Commit

Permalink
update: optimize DaleStudy#276 time complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
lymchgmk committed Oct 21, 2024
1 parent 50af881 commit ac155d9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions jump-game/EGON.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ def canJump(self, nums: List[int]) -> bool:
return self.solve_dp(nums)

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

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

Expand Down

0 comments on commit ac155d9

Please sign in to comment.