{"id":2588,"date":"2018-07-22T14:36:20","date_gmt":"2018-07-22T06:36:20","guid":{"rendered":"https:\/\/nodelay.xyz\/?p=2588"},"modified":"2018-07-22T14:36:20","modified_gmt":"2018-07-22T06:36:20","slug":"some-of-the-best-answers-to-leetcode-questions","status":"publish","type":"post","link":"https:\/\/dayandcarrot.space\/?p=2588","title":{"rendered":"Some of the best answers to LeetCode questions"},"content":{"rendered":"<p>Here I gathered some of (what I thought are) best answers to LeetCode questions:<\/p>\n<ul>\n<li>https:\/\/leetcode.com\/problems\/wiggle-subsequence\/discuss\/84887\/C++-0ms-O(N)-dynamic-programming-solution\n<ul>\n<li>an O(n) solution<\/li>\n<\/ul>\n<\/li>\n<li>https:\/\/leetcode.com\/problems\/trapping-rain-water\/description\/\n<ul>\n<li>an O(n) solution of a similar (but harder) question, found in the book &lt;\u7b97\u6cd5\u7ade\u8d5b\u5165\u95e8\u7ecf\u5178(\u7b2c\u4e8c\u7248) pp249\u4f8b8-18<\/li>\n<li>basic idea is to find a maximal height which can reserve the water for each position i, if the max height equals to the unit then no rain can be collected at i<\/li>\n<li><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-2592\" title=\"trapping rain\" src=\"https:\/\/boweihe.xyz\/wp-content\/uploads\/2018\/07\/trapping-rain.png\" sizes=\"auto, (max-width: 301px) 100vw, 301px\" srcset=\"https:\/\/boweihe.xyz\/wp-content\/uploads\/2018\/07\/trapping-rain.png 301w, https:\/\/boweihe.xyz\/wp-content\/uploads\/2018\/07\/trapping-rain-300x190.png 300w\" alt=\"\" width=\"301\" height=\"191\" \/>(vice versa, from right to left)<\/li>\n<\/ul>\n<\/li>\n<li><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Here I gathered some of (what I thought are) best answers to LeetCode questions: https:\/\/leetcode.com\/problems\/wiggle-subsequence\/discuss\/84887\/C++-0ms-O(N)-dynamic-programming-solution an O(n) solution https:\/\/leetcode.com\/problems\/trapping-rain-water\/description\/ an O(n) solution of a similar (but harder) question, found in the book &lt;\u7b97\u6cd5\u7ade\u8d5b\u5165\u95e8\u7ecf\u5178(\u7b2c\u4e8c\u7248) pp249\u4f8b8-18 basic idea is to find a maximal height which can reserve the water for each position i, if the max height [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-2588","post","type-post","status-publish","format-standard","hentry","category-study"],"_links":{"self":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/2588","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2588"}],"version-history":[{"count":0,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/2588\/revisions"}],"wp:attachment":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2588"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2588"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2588"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}