{"id":314,"date":"2025-06-29T14:55:00","date_gmt":"2025-06-29T06:55:00","guid":{"rendered":"http:\/\/getzs.online\/?p=314"},"modified":"2025-06-30T22:41:51","modified_gmt":"2025-06-30T14:41:51","slug":"45-%e8%b7%b3%e8%b7%83%e6%b8%b8%e6%88%8f-ii","status":"publish","type":"post","link":"https:\/\/hello.getzs.online\/index.php\/2025\/06\/29\/45-%e8%b7%b3%e8%b7%83%e6%b8%b8%e6%88%8f-ii\/","title":{"rendered":"45. \u8df3\u8dc3\u6e38\u620f II"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode.cn\/problems\/jump-game-ii\/\">45. \u8df3\u8dc3\u6e38\u620f II<\/a><\/p>\n\n\n\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a&nbsp;<code>n<\/code>&nbsp;\u7684&nbsp;<strong>0 \u7d22\u5f15<\/strong>\u6574\u6570\u6570\u7ec4&nbsp;<code>nums<\/code>\u3002\u521d\u59cb\u4f4d\u7f6e\u4e3a&nbsp;<code>nums[0]<\/code>\u3002<\/p>\n\n\n\n<p>\u6bcf\u4e2a\u5143\u7d20&nbsp;<code>nums[i]<\/code>&nbsp;\u8868\u793a\u4ece\u7d22\u5f15&nbsp;<code>i<\/code>&nbsp;\u5411\u540e\u8df3\u8f6c\u7684\u6700\u5927\u957f\u5ea6\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u5982\u679c\u4f60\u5728&nbsp;<code>nums[i]<\/code>&nbsp;\u5904\uff0c\u4f60\u53ef\u4ee5\u8df3\u8f6c\u5230\u4efb\u610f&nbsp;<code>nums[i + j]<\/code>&nbsp;\u5904:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>0 &lt;= j &lt;= nums[i]<\/code>\u00a0<\/li>\n\n\n\n<li><code>i + j &lt; n<\/code><\/li>\n<\/ul>\n\n\n\n<p>\u8fd4\u56de\u5230\u8fbe&nbsp;<code>nums[n - 1]<\/code>&nbsp;\u7684\u6700\u5c0f\u8df3\u8dc3\u6b21\u6570\u3002\u751f\u6210\u7684\u6d4b\u8bd5\u7528\u4f8b\u53ef\u4ee5\u5230\u8fbe&nbsp;<code>nums[n - 1]<\/code>\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165:<\/strong> nums = [2,3,1,1,4]\n<strong>\u8f93\u51fa:<\/strong> 2\n<strong>\u89e3\u91ca:<\/strong> \u8df3\u5230\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e\u7684\u6700\u5c0f\u8df3\u8dc3\u6570\u662f <code>2<\/code>\u3002\n&nbsp;    \u4ece\u4e0b\u6807\u4e3a 0 \u8df3\u5230\u4e0b\u6807\u4e3a 1 \u7684\u4f4d\u7f6e\uff0c\u8df3&nbsp;<code>1<\/code>&nbsp;\u6b65\uff0c\u7136\u540e\u8df3&nbsp;<code>3<\/code>&nbsp;\u6b65\u5230\u8fbe\u6570\u7ec4\u7684\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e\u3002\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 2:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165:<\/strong> nums = [2,3,0,1,4]\n<strong>\u8f93\u51fa:<\/strong> 2\n<\/pre>\n\n\n\n<p><strong>\u63d0\u793a:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>1 &lt;= nums.length &lt;= 10<sup>4<\/sup><\/code><\/li>\n\n\n\n<li><code>0 &lt;= nums[i] &lt;= 1000<\/code><\/li>\n\n\n\n<li>\u9898\u76ee\u4fdd\u8bc1\u53ef\u4ee5\u5230\u8fbe\u00a0<code>nums[n-1]<\/code><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>    public int jump(int&#91;] nums) {\n        return method1(nums, nums.length);\n    }\n\n    \/**\n     * \u8d2a\u5fc3\n     * 1 ms\n     * \u590d\u6742\u5ea6O(n)\n     *\/\n    public int method1(int&#91;] nums, int n) {\n        int count = 0, step = 0, mx = 0;\n        for (int i = 0 ; i &lt; n &amp;&amp; step &lt; n - 1 ; i++) {\n            \/\/ \u83b7\u53d6\u53ef\u4ee5\u8fbe\u5230\u7684\u6700\u8fdc\u8ddd\u79bb\n            mx = Math.max(mx, i + nums&#91;i]);\n            \/\/ \u4e0a\u4e00\u6b65\uff08\u6700\u5c11\u7684\u6b65\u6570\uff09\u53ef\u4ee5\u5230\u8fbe\u7684\u6700\u8fdc\u8ddd\u79bb\n            if (step == i) {\n                count++;\n                step = mx;\n            }\n        }\n        return count;\n    }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>45. \u8df3\u8dc3\u6e38\u620f II \u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a&nbsp;n&nbsp;\u7684&nbsp;0 \u7d22\u5f15\u6574\u6570\u6570\u7ec4&nbsp;nu [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,11],"tags":[],"class_list":["post-314","post","type-post","status-publish","format-standard","hentry","category-leetcode"],"_links":{"self":[{"href":"https:\/\/hello.getzs.online\/index.php\/wp-json\/wp\/v2\/posts\/314","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hello.getzs.online\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hello.getzs.online\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hello.getzs.online\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hello.getzs.online\/index.php\/wp-json\/wp\/v2\/comments?post=314"}],"version-history":[{"count":1,"href":"https:\/\/hello.getzs.online\/index.php\/wp-json\/wp\/v2\/posts\/314\/revisions"}],"predecessor-version":[{"id":315,"href":"https:\/\/hello.getzs.online\/index.php\/wp-json\/wp\/v2\/posts\/314\/revisions\/315"}],"wp:attachment":[{"href":"https:\/\/hello.getzs.online\/index.php\/wp-json\/wp\/v2\/media?parent=314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hello.getzs.online\/index.php\/wp-json\/wp\/v2\/categories?post=314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hello.getzs.online\/index.php\/wp-json\/wp\/v2\/tags?post=314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}