码迷,mamicode.com
首页 > 其他好文 > 详细

LeetCode "Jump Game"

时间:2014-08-01 13:16:01      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   div   amp   log   leetcode   

A simulation problem. We simple walk through all reachable items until we cannot proceed.

class Solution {
public:
    bool canJump(int A[], int n) {

        int MaxInx = 0;
        int inx = 0;
        while (inx < n && inx <= MaxInx)
        {
            MaxInx = std::max(MaxInx, A[inx] + inx);
            if (MaxInx >= n - 1) return true;
            inx++;
        }

        return false;
    }
};

LeetCode "Jump Game",布布扣,bubuko.com

LeetCode "Jump Game"

标签:style   blog   color   io   div   amp   log   leetcode   

原文地址:http://www.cnblogs.com/tonix/p/3884480.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!