Leetcode Oj:jump Game (jumping games)

Source: Internet
Author: User
Tags jumping games

Given an array of non-negative integers, you is initially positioned at the first index of the array.

Each element of the array represents your maximum jump length is at that position.

Determine if you is able to reach the last index.

For example:
A = [2,3,1,1,4] , return true .

A = [3,2,1,0,4] , return false .

Note that the number on each bit here is the maximum length that can be jumped, should use greedy strategy, see other people's implementation, code as follows, think about it later:

1 classSolution {2  Public:3     BOOLCanjump (vector<int>&nums) {4         intSZ =nums.size ();5         if(!SZ)return false;6         intleft = nums[0];7          for(inti =1; I < sz; ++i)8             if(Left >0){9left--;Tenleft =Max (left, nums[i]); One}Else return false; A         return true; -     } -};

Leetcode Oj:jump Game (jumping games)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.