{
  "type": "code_options",
  "author": "https://github.com/begeekmyfriend/leetcode",
  "source": "solution.md",
  "exercise_id": "837128c8eb2c481ba2cb3ca390a5df10",
  "keywords": "贪心,数组,动态规划",
  "title": "跳跃游戏 II",
  "desc": [
    {
      "content": "\n<p>给定一个非负整数数组，你最初位于数组的第一个位置。</p>\n<p>数组中的每个元素代表你在该位置可以跳跃的最大长度。</p>\n<p>你的目标是使用最少的跳跃次数到达数组的最后一个位置。</p>\n<p><strong>示例:</strong></p>\n<pre><strong>输入:</strong> [2,3,1,1,4]<strong><br />输出:</strong> 2<strong><br />解释:</strong> 跳到最后一个位置的最小跳跃数是 2。从下标为 0 跳到下标为 1 的位置，跳&nbsp;1&nbsp;步，然后跳&nbsp;3&nbsp;步到达数组的最后一个位置。</pre>\n<p><strong>说明:</strong></p>\n<p>假设你总是可以到达数组的最后一个位置。</p>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "cpp"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ]
  ],
  "template": {
    "content": "#include <bits/stdc++.h>\nusing namespace std;\nclass Solution\n{\npublic:\n\tint jump(vector<int> &nums)\n\t{\n\t\tint steps = 0;\n\t\tint lo = 0, hi = 0;\n\t\twhile (hi < nums.size() - 1)\n\t\t{\n\t\t\tint right = 0;\n\t\t\tfor (int i = lo; i <= hi; i++)\n\t\t\t{\n\t\t\t\tright = max(i + nums[i], right);\n\t\t\t}\n\t\t\tlo = hi + 1;\n\t\t\thi = right;\n\t\t\tsteps++;\n\t\t}\n\t\treturn steps;\n\t}\n};",
    "language": "cpp"
  },
  "node_id": "dailycode-a6c3e70f1c0045c1b2929f56cc5ce02f",
  "license": "csdn.net",
  "created_at": 1637894158,
  "topic_link": "https://bbs.csdn.net/topics/600469921"
}