Tony's Log

Algorithms, Distributed System, Machine Learning

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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;
    }
};
posted on 2014-08-01 11:11  Tonix  阅读(104)  评论(0编辑  收藏  举报