{"id":2912,"date":"2020-02-09T15:38:41","date_gmt":"2020-02-09T07:38:41","guid":{"rendered":"http:\/\/www.sniper97.cn\/?p=2912"},"modified":"2020-02-09T15:38:41","modified_gmt":"2020-02-09T07:38:41","slug":"%e3%80%90leetcode%e3%80%910045-%e8%b7%b3%e8%b7%83%e6%b8%b8%e6%88%8f","status":"publish","type":"post","link":"http:\/\/www.sniper97.cn\/index.php\/note\/algorithm\/2912\/","title":{"rendered":"\u3010LeetCode\u30110045 \u8df3\u8dc3\u6e38\u620f"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode-cn.com\/problems\/jump-game-ii\/\">https:\/\/leetcode-cn.com\/problems\/jump-game-ii\/<\/a><\/p>\n\n\n<pre class=\"wp-block-preformatted\"># -*- coding:utf-8 -*-<em>\n<\/em>class Solution(object):\n    def jump(self, nums):\n        <em>\"\"\"\n        <\/em><strong><em>:type<\/em><\/strong><em> nums: List[int]\n        <\/em><strong><em>:rtype<\/em><\/strong><em>: int\n        \"\"\"\n        <\/em>step = 0\n        end = 0\n        max_bound = 0\n        for i in range(len(nums) - 1):\n            max_bound = max(max_bound, nums[i] + i)\n            if (i == end):\n                step += 1\n                end = max_bound\n        return step\nif __name__ == '__main__':\n    nums = [2, 3, 1, 1, 4]\n    nums = [3, 2, 1]\n    # nums = [1, 1, 1, 1]\n    print(Solution().jump(nums))\n<\/pre>\n\n\n<p>\u8d2a\u5fc3\u89e3\u51b3\uff0c\u627e\u5230\u76ee\u524d\u80fd\u8df3\u5230\u6700\u8fdc\u7684\u8ddd\u79bb\u3002\u6bd4\u5982[1,1,1,1] \u5728idx=1\u7684\u65f6\u5019\uff0c\u6700\u8fdc\u80fd\u8df3\u52302\uff081+1\uff09\uff0c\u56e0\u6b64end=max=2\uff0c\u5f53idx=2\u65f6\uff0c\u6700\u8fdc\u80fd\u8df3\u52303\uff081+2\uff09\u56e0\u6b64end =max =3\u3002<\/p>\n\n\n<p>\u6bd4\u5982[2,3,1,1,4]\uff0cidx0\u65f6\uff0cend =max =2\uff0cidx1\u65f6\uff0cmax=end=1+3=4\uff0cidx2\u65f6\uff0c1+2&lt;max=end\uff0c\u56e0\u6b64\u4e0d\u66f4\u65b0\uff0c\u5f53idx3\u65f6\uff0c1+3=4,\u66f4\u65b0\u3002\u56e0\u6b64\u6211\u4eec\u627e\u51fa\u4e86\u4e09\u6b21\u66f4\u65b0\uff0cidx\u5206\u522b\u4e3a0 1 3.\u4e5f\u5c31\u662f\u4e09\u6b21\u8df3\u8f6c\u7684\u5730\u65b9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/leetcode-cn.com\/problems\/jump-game-ii\/ # &#8211; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[10],"tags":[],"views":1552,"_links":{"self":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2912"}],"collection":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/comments?post=2912"}],"version-history":[{"count":0,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2912\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2912"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2912"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2912"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}