| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 |
Tags
- GenAI
- 리트코드
- array
- nlp
- 릿코드
- 생성형AI
- SQL
- LeetCode
- stratascratch
- GenerativeAI
- 파이썬
- 투포인터
- 슬라이딩윈도우
- 알고리즘
- sql코테
- BFS
- 코드업
- graph
- heap
- Stack
- 파이썬알고리즘
- two-pointer
- binary Tree
- codeup
- dfs
- Greedy
- Python3
- Python
- 니트코드
- tree
Archives
- Today
- Total
Tech for good
[Leetcode/Greedy] 55. Jump Game 본문

https://leetcode.com/problems/jump-game/description/
class Solution:
def canJump(self, nums: List[int]) -> bool:
max_reach = 0
for i in range(len(nums)):
if i > max_reach:
return False # Current index is unreachable
max_reach = max(max_reach, i + nums[i]) # Update the farthest reachable index
return True
✅ Explanation:
- max_reach keeps track of the furthest index you can reach at any point.
- For every index i:
- If i > max_reach, it means you’re stuck and can’t move forward — return False.
- Otherwise, update max_reach as the furthest you can go from the current position.
- If the loop completes, it means all indices are reachable — return True.
'IT > Computer Science' 카테고리의 다른 글
| [Leetcode/Stack] 1047. Remove All Adjacent Duplicates In String (0) | 2025.06.11 |
|---|---|
| [CodePath] Unit 1: Strings and Arrays - Unique (0) | 2025.06.11 |
| [Leetcode/Linked List] 206. Reverse Linked List (0) | 2025.06.03 |
| [Leetcode/Graph (In-Degree/Out-Degree)] 277. Find the Celebrity (0) | 2025.06.02 |
| [Leetcode/Graph (In-Degree/Out-Degree)] 997. Find the Town Judge (0) | 2025.06.02 |