{"id":2272,"date":"2022-01-22T17:51:21","date_gmt":"2022-01-22T09:51:21","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2272"},"modified":"2022-01-22T17:51:22","modified_gmt":"2022-01-22T09:51:22","slug":"leetcodeday56","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/22\/leetcodeday56\/","title":{"rendered":"leetcodeday56 &#8211;\u5408\u5e76\u533a\u95f4"},"content":{"rendered":"\n<p>\u4ee5\u6570\u7ec4&nbsp;<code>intervals<\/code>&nbsp;\u8868\u793a\u82e5\u5e72\u4e2a\u533a\u95f4\u7684\u96c6\u5408\uff0c\u5176\u4e2d\u5355\u4e2a\u533a\u95f4\u4e3a&nbsp;<code>intervals[i] = [start<sub>i<\/sub>, end<sub>i<\/sub>]<\/code>&nbsp;\u3002\u8bf7\u4f60\u5408\u5e76\u6240\u6709\u91cd\u53e0\u7684\u533a\u95f4\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u4e0d\u91cd\u53e0\u7684\u533a\u95f4\u6570\u7ec4\uff0c\u8be5\u6570\u7ec4\u9700\u6070\u597d\u8986\u76d6\u8f93\u5165\u4e2d\u7684\u6240\u6709\u533a\u95f4\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>intervals = [[1,3],[2,6],[8,10],[15,18]]\n<strong>\u8f93\u51fa\uff1a<\/strong>[[1,6],[8,10],[15,18]]\n<strong>\u89e3\u91ca\uff1a<\/strong>\u533a\u95f4 [1,3] \u548c [2,6] \u91cd\u53e0, \u5c06\u5b83\u4eec\u5408\u5e76\u4e3a [1,6].\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>intervals = [[1,4],[4,5]]\n<strong>\u8f93\u51fa\uff1a<\/strong>[[1,5]]\n<strong>\u89e3\u91ca\uff1a<\/strong>\u533a\u95f4 [1,4] \u548c [4,5] \u53ef\u88ab\u89c6\u4e3a\u91cd\u53e0\u533a\u95f4\u3002<\/pre>\n\n\n\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n\n\n\n<ul><li><code>1 &lt;= intervals.length &lt;= 10<sup>4<\/sup><\/code><\/li><li><code>intervals[i].length == 2<\/code><\/li><li><code>0 &lt;= start<sub>i<\/sub>&nbsp;&lt;= end<sub>i<\/sub>&nbsp;&lt;= 10<sup>4<\/sup><\/code><\/li><\/ul>\n\n\n\n<p>\u7b2c\u4e00\u6b21\u5c1d\u8bd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># &#91;56] \u5408\u5e76\u533a\u95f4\r\n#\r\n\r\n# @lc code=start\r\nclass Solution:\r\n    def merge(self, intervals: List&#91;List&#91;int]]) -> List&#91;List&#91;int]]:\r\n        # def takeSecond(elem):\r\n        #     return elem&#91;0]\r\n       \r\n        # intervals.sort(key=takeSecond)       \r\n        def submatch(intervals):\r\n            rev=list()\r\n            i=0\r\n            j=0\r\n            lens=len(intervals)\r\n            intervals.sort(key=lambda x: (x&#91;0], x&#91;1]))\r\n            maxy=0 \r\n            while i&lt;lens:\r\n                maxy=max(maxy,intervals&#91;i]&#91;1])          \r\n                if j&lt;lens-1 and intervals&#91;i]&#91;1]>=intervals&#91;j+1]&#91;0]:\r\n                    maxy=max(maxy,intervals&#91;j+1]&#91;1])   \r\n                    j=j+1         \r\n                else:\r\n                    maxy=max(maxy,intervals&#91;j]&#91;1]) \r\n                    rev.append(&#91;intervals&#91;i]&#91;0],maxy])\r\n                    i=j+1\r\n                    j=i\r\n            return rev\r\n        \r\n        rev=submatch(intervals)\r\n        while rev!=submatch(rev):\r\n            rev=submatch(rev)\r\n        return rev<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-268.png\" alt=\"\" class=\"wp-image-2276\" width=\"505\" height=\"158\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-268.png 747w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-268-300x94.png 300w\" sizes=\"(max-width: 505px) 100vw, 505px\" \/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee5\u6570\u7ec4&nbsp;intervals&nbsp;\u8868\u793a\u82e5\u5e72\u4e2a\u533a\u95f4\u7684\u96c6\u5408\uff0c\u5176\u4e2d\u5355\u4e2a\u533a\u95f4\u4e3a&nbsp;interva &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/22\/leetcodeday56\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday56 &#8211;\u5408\u5e76\u533a\u95f4<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2272"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=2272"}],"version-history":[{"count":5,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2272\/revisions"}],"predecessor-version":[{"id":2279,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2272\/revisions\/2279"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2272"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}