{
  "type": "code_options",
  "author": "https://github.com/begeekmyfriend/leetcode",
  "source": "solution.md",
  "exercise_id": "6b2821c095b94e7499a60edc54515517",
  "keywords": "贪心,数组,动态规划",
  "title": "跳跃游戏",
  "desc": [
    {
      "content": "\n<p>给定一个非负整数数组 <code>nums</code> ，你最初位于数组的 <strong>第一个下标</strong> 。</p><p>数组中的每个元素代表你在该位置可以跳跃的最大长度。</p><p>判断你是否能够到达最后一个下标。</p><p> </p><p><strong>示例 1：</strong></p><pre><strong>输入：</strong>nums = [2,3,1,1,4]<strong><br />输出：</strong>true<strong><br />解释：</strong>可以先跳 1 步，从下标 0 到达下标 1, 然后再从下标 1 跳 3 步到达最后一个下标。</pre><p><strong>示例 2：</strong></p><pre><strong>输入：</strong>nums = [3,2,1,0,4]<strong><br />输出：</strong>false<strong><br />解释：</strong>无论怎样，总会到达下标为 3 的位置。但该下标的最大跳跃长度是 0 ， 所以永远不可能到达最后一个下标。</pre><p> </p><p><strong>提示：</strong></p><ul>\t<li><code>1 <= nums.length <= 3 * 10<sup>4</sup></code></li>\t<li><code>0 <= nums[i] <= 10<sup>5</sup></code></li></ul>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "cpp"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ]
  ],
  "template": {
    "content": "#include <stdio.h>\n#include <stdlib.h>\n#include <stdbool.h>\nstatic inline int max(int a, int b)\n{\n\treturn a > b ? a : b;\n}\nstatic bool canJump(int *nums, int numsSize)\n{\n\tint i, pos = 0;\n\tfor (i = 0; i < numsSize - 1; i++)\n\t{\n\t\tif (pos < i || pos >= numsSize - 1)\n\t\t{\n\t\t\tbreak;\n\t\t}\n\t\tpos = max(i + nums[i], pos);\n\t}\n\treturn pos >= numsSize - 1;\n}\nint main(int argc, char **argv)\n{\n\tint i, count = argc - 1;\n\tint *nums = malloc(count * sizeof(int));\n\tfor (i = 0; i < count; i++)\n\t{\n\t\tnums[i] = atoi(argv[i + 1]);\n\t}\n\tprintf(\"%s\\n\", canJump(nums, count) ? \"true\" : \"false\");\n\treturn 0;\n}",
    "language": "cpp"
  },
  "node_id": "dailycode-d5fa1747371e4789932aeed9ee27bcdb",
  "license": "csdn.net",
  "created_at": 1637894158,
  "topic_link": "https://bbs.csdn.net/topics/600470122"
}