题解 | #跳跃游戏(一)#

跳跃游戏(一)

http://www.nowcoder.com/practice/07484f4377344d3590045a095910992b

import java.io.*; public class Main{ public static void main(String[] args)throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String str = null; while((str = in.readLine()) != null){ int n = Integer.parseInt(str); String[] arr = in.readLine().split(" "); int[] res = new int[n]; for(int i = 0;i < n;i++){ res[i] = Integer.parseInt(arr[i]); } int post = 0; int flag = 0; for(int index = 0;index < n;index ++){ if(index > post){ flag = 1; break; } post = Math.max(res[index]+index,post); if(post >= n-1){ break; }

        }
        if(flag == 0){
            System.out.println(true);
        }else{
            System.out.println(false);
        }
    }
}

}

我居南半坡 文章被收录于专栏

多刷题,积蓄力量,欢迎讨论

全部评论

相关推荐

点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务