{"id":2096,"date":"2022-01-16T13:11:27","date_gmt":"2022-01-16T05:11:27","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2096"},"modified":"2022-01-16T13:11:28","modified_gmt":"2022-01-16T05:11:28","slug":"leetcodeday34","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/16\/leetcodeday34\/","title":{"rendered":"leetcodeday34 &#8211;\u5728\u6392\u5e8f\u6570\u7ec4\u4e2d\u67e5\u627e\u5143\u7d20\u7684\u7b2c\u4e00\u4e2a\u548c\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e"},"content":{"rendered":"\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u6309\u7167\u5347\u5e8f\u6392\u5217\u7684\u6574\u6570\u6570\u7ec4&nbsp;<code>nums<\/code>\uff0c\u548c\u4e00\u4e2a\u76ee\u6807\u503c&nbsp;<code>target<\/code>\u3002\u627e\u51fa\u7ed9\u5b9a\u76ee\u6807\u503c\u5728\u6570\u7ec4\u4e2d\u7684\u5f00\u59cb\u4f4d\u7f6e\u548c\u7ed3\u675f\u4f4d\u7f6e\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u6570\u7ec4\u4e2d\u4e0d\u5b58\u5728\u76ee\u6807\u503c&nbsp;<code>target<\/code>\uff0c\u8fd4\u56de&nbsp;<code>[-1, -1]<\/code>\u3002<\/p>\n\n\n\n<p><strong>\u8fdb\u9636\uff1a<\/strong><\/p>\n\n\n\n<ul><li>\u4f60\u53ef\u4ee5\u8bbe\u8ba1\u5e76\u5b9e\u73b0\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a&nbsp;<code>O(log n)<\/code>&nbsp;\u7684\u7b97\u6cd5\u89e3\u51b3\u6b64\u95ee\u9898\u5417\uff1f<\/li><\/ul>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>nums = &#91;5,7,7,8,8,10], target = 8\n<strong>\u8f93\u51fa\uff1a<\/strong>&#91;3,4]<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>nums = &#91;5,7,7,8,8,10], target = 6\n<strong>\u8f93\u51fa\uff1a<\/strong>&#91;-1,-1]<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 3\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>nums = &#91;], target = 0\n<strong>\u8f93\u51fa\uff1a<\/strong>&#91;-1,-1]<\/code><\/pre>\n\n\n\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n\n\n\n<ul><li><code>0 &lt;= nums.length &lt;= 10<sup>5<\/sup><\/code><\/li><li><code>-10<sup>9<\/sup>&nbsp;&lt;= nums[i]&nbsp;&lt;= 10<sup>9<\/sup><\/code><\/li><li><code>nums<\/code>&nbsp;\u662f\u4e00\u4e2a\u975e\u9012\u51cf\u6570\u7ec4<\/li><li><code>-10<sup>9<\/sup>&nbsp;&lt;= target&nbsp;&lt;= 10<sup>9<\/sup><\/code><\/li><\/ul>\n\n\n\n<p>\u76f4\u63a5\u7ed9\u51fa\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc code=start\r\nclass Solution:\r\n    def searchRange(self, nums: List&#91;int], target: int) -> List&#91;int]:\r\n        j=len(nums)-1\r\n        i=0\r\n        while i&lt;=j:\r\n            if nums&#91;i]!=target:\r\n                i=i+1\r\n            if nums&#91;j]!=target:\r\n                j=j-1\r\n            if nums&#91;j]==target and nums&#91;i]==target:\r\n                return &#91;i,j]\r\n        return &#91;-1,-1]\r\n\r\n# @lc code=end\r\n<\/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-232.png\" alt=\"\" class=\"wp-image-2100\" width=\"487\" height=\"120\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-232.png 738w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-232-300x74.png 300w\" sizes=\"(max-width: 487px) 100vw, 487px\" \/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5b9a\u4e00\u4e2a\u6309\u7167\u5347\u5e8f\u6392\u5217\u7684\u6574\u6570\u6570\u7ec4&nbsp;nums\uff0c\u548c\u4e00\u4e2a\u76ee\u6807\u503c&nbsp;target\u3002\u627e\u51fa\u7ed9\u5b9a\u76ee\u6807\u503c\u5728\u6570\u7ec4 &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/16\/leetcodeday34\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday34 &#8211;\u5728\u6392\u5e8f\u6570\u7ec4\u4e2d\u67e5\u627e\u5143\u7d20\u7684\u7b2c\u4e00\u4e2a\u548c\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e<\/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\/2096"}],"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=2096"}],"version-history":[{"count":3,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2096\/revisions"}],"predecessor-version":[{"id":2101,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2096\/revisions\/2101"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2096"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2096"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2096"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}