LeetCode 풀기 - 55. Jump Game

백지우·2026년 9월 15일

LeetCode

목록 보기
50/76
  • LeetCode 최소 하루에 하나는 풀자는 마인드
  • 사용언어: JAVA

55. Jump Game

풀이

  • 방법: Greedy Algorithm을 사용하여 가장 멀리갈 수 있는 거리를 기록, 만약 index가 현재 갈수 있는 최대 위치보다 커지면 false
class Solution {
    public boolean canJump(int[] nums) {
        int maxReach = 0;

        for(int i = 0; i < nums.length; i++){
            if(i > maxReach) return false;
            maxReach = Math.max(maxReach, i + nums[i]);

            if(maxReach >= nums.length-1) return true;
        }
        return false;
    }
}

0개의 댓글