{"id":8951,"date":"2021-12-01T08:43:09","date_gmt":"2021-12-01T16:43:09","guid":{"rendered":"https:\/\/zxi.mytechroad.com\/blog\/?p=8951"},"modified":"2021-12-01T08:44:26","modified_gmt":"2021-12-01T16:44:26","slug":"leetcode-ultimate-dp-study-plan-day-4","status":"publish","type":"post","link":"https:\/\/zxi.mytechroad.com\/blog\/dynamic-programming\/leetcode-ultimate-dp-study-plan-day-4\/","title":{"rendered":"\u82b1\u82b1\u9171 LeetCode Ultimate DP Study Plan Day 4"},"content":{"rendered":"\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"LeetCode DP\u7ec8\u6781\u5b66\u4e60\u8ba1\u5212\uff01Day4 Jump Game I\/II \u3010\u8ddf\u6211\u4e00\u8d77\u5199\u4ee3\u7801\u3011\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/3mIc_mKP4yM?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>55 Jump Game<\/strong><\/h2>\n\n\n\n<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">Python3<\/h2>\n<div class=\"tabcontent\">\n\n<pre lang=\"python\">\n# Author: Huahua\n# Time complexity: O(n^2)\n# Space complexity: O(n)\nclass Solution:\n  def canJump(self, nums: List[int]) -> bool:\n    n = len(nums)\n    \n    @cache\n    def dp(i: int) -> bool:\n      \"\"\"Returns whether we can reach n - 1 from i.\"\"\"\n      if i >= n - 1: return True\n      if i + nums[i] >= n - 1: return True\n      for s in range(1, nums[i] + 1):\n        if dp(i + s): return True\n      return False\n    \n    return dp(0)\n<\/pre>\n<\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>45 Jump Game II<\/strong><\/h2>\n\n\n\n<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">Python3<\/h2>\n<div class=\"tabcontent\">\n\n<pre lang=\"python\">\n# Author: Huahua\n# Time complexity: O(n^2)\n# Space complexity: O(n)\nclass Solution:\n  def jump(self, nums: List[int]) -> int:\n    n = len(nums)\n    \n    @cache\n    def dp(i: int) -> int:\n      \"\"\"Min steps to reach n - 1 from i.\"\"\"\n      if i >= n - 1: return 0\n      if i + nums[i] >= n - 1: return 1\n      ans = n\n      for s in range(1, nums[i] + 1):\n        ans = min(ans, dp(i + s) + 1)\n      return ans\n    \n    return dp(0)\n<\/pre>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>55 Jump Game # Author: Huahua # Time complexity: O(n^2) # Space complexity: O(n) class Solution: def canJump(self, nums: List[int]) -> bool: n = len(nums)&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[740,18],"class_list":["post-8951","post","type-post","status-publish","format-standard","hentry","category-dynamic-programming","tag-coding-with-me","tag-dp","entry","simple"],"_links":{"self":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/8951","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/comments?post=8951"}],"version-history":[{"count":2,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/8951\/revisions"}],"predecessor-version":[{"id":8953,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/8951\/revisions\/8953"}],"wp:attachment":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/media?parent=8951"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/categories?post=8951"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/tags?post=8951"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}