End of Array Reachable

语言

Given an array of integers numbers where each element in the array represents the maximum number of positions that can be moved forward from that index; it is acceptable to move by fewer positions.

Determine whether it is possible to reach the last index of the array by starting from the first index. Return true if it can be reached and false otherwise.

Input

  • numbers: number[]: An array of integers, each index's value is the maximum number of positions reachable from that index

Examples

Input: numbers = [4,1,0,0,2,3]
Output: true
Explanation: Move from index 0 to 4, then move 1 position to the last index.
Input: numbers = [1,0,0,0]
Output: false
Explanation: Can only move from index 0 to index 1 and no further movements thereafter, so it impossible to reach the last index.
Input: numbers = [2,3,1,1,4]
Output: true
Explanation: Move 1 position forward from index 0 to index 1 (it is allowed to move up to 2 positions, but going to index 1 first allows us to move further). From index 1, move 3 positions to reach the last index.

Constraints

  • 1 <= numbers.length <= 10,000
  • 0 <= numbers[i] <= 100,000
SwagOverflow — Swag tailored for front end devs赞助商:SwagOverflow
SwagOverflow — Swag tailored for front end devs

Looking for a gift for a fellow dev, or a simple comfy t-shirt that expresses your passion for front end?

Check out SwagOverflow, your ultimate destination for dev-centric apparel and accessories. Whether you’re coding at your favorite café or speaking at a local meetup, our products will help you stand out in any crowd. Here’s why you’ll love SwagOverflow:

  • Unique, dev-Inspired designs: From HTML tags to CSS puns, show off your coding chops
  • Premium quality materials: Made to handle all-night coding sessions or weekend hackathons
  • Variety for every stack: React lover? TypeScript fanatic? We’ve got you covered
  • Perfect gifts for techies: Surprise a friend (or yourself) with front end flair
  • Community-focused: A portion of every purchase goes right back into supporting dev communities
Visit SwagOverflow today ->
SwagOverflow — Swag tailored for front end devs赞助商:SwagOverflow
SwagOverflow — Swag tailored for front end devs

Looking for a gift for a fellow dev, or a simple comfy t-shirt that expresses your passion for front end?

Check out SwagOverflow, your ultimate destination for dev-centric apparel and accessories. Whether you’re coding at your favorite café or speaking at a local meetup, our products will help you stand out in any crowd. Here’s why you’ll love SwagOverflow:

  • Unique, dev-Inspired designs: From HTML tags to CSS puns, show off your coding chops
  • Premium quality materials: Made to handle all-night coding sessions or weekend hackathons
  • Variety for every stack: React lover? TypeScript fanatic? We’ve got you covered
  • Perfect gifts for techies: Surprise a friend (or yourself) with front end flair
  • Community-focused: A portion of every purchase goes right back into supporting dev communities
Visit SwagOverflow today ->
zh-CN的翻译是测试版,可能不准确。 如果您有兴趣帮助翻译,请提供反馈或联系我们