aboutsummaryrefslogtreecommitdiff
path: root/works/solutions/leetcode/cpp/55.cpp
blob: d2c26003e81300e5b64f451b0655bc121e8c6432 (plain)
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
#include <vector>

using std::vector;

#include <algorithm>

class Solution
{
public:
    bool canJump(vector<int> &nums)
    {
        int max = 0;
        const int size = nums.size();
        for (int i = 0; i < size; i++)
        {
            if (i <= max)
            {
                max = std::max(max, i + nums[i]);
                if (max >= size - 1)
                    return true;
            }
            else
            {
                return false;
            }
        }
        return false;
    }
};