{"id":662,"date":"2022-01-27T21:28:13","date_gmt":"2022-01-27T13:28:13","guid":{"rendered":"https:\/\/bigwer.cn\/?p=662"},"modified":"2022-03-13T21:28:32","modified_gmt":"2022-03-13T13:28:32","slug":"lc977","status":"publish","type":"post","link":"https:\/\/bigwer.cn\/index.php\/2022\/01\/27\/lc977\/","title":{"rendered":"lc977.\u6709\u5e8f\u6570\u7ec4\u7684\u5e73\u65b9"},"content":{"rendered":"<p><div class=\"has-toc have-toc\"><\/div><br \/>\n<a href=\"https:\/\/leetcode-cn.com\/problems\/squares-of-a-sorted-array\/submissions\/\" target=\"_blank\"  rel=\"nofollow\" >977. \u6709\u5e8f\u6570\u7ec4\u7684\u5e73\u65b9<\/a><\/p>\n<blockquote>\n<p>\u7ed9\u4f60\u4e00\u4e2a\u6309 <strong>\u975e\u9012\u51cf\u987a\u5e8f<\/strong> \u6392\u5e8f\u7684\u6574\u6570\u6570\u7ec4 <strong>nums<\/strong>\uff0c\u8fd4\u56de <strong>\u6bcf\u4e2a\u6570\u5b57\u7684\u5e73\u65b9<\/strong> \u7ec4\u6210\u7684\u65b0\u6570\u7ec4\uff0c\u8981\u6c42\u4e5f\u6309 <strong>\u975e\u9012\u51cf\u987a\u5e8f<\/strong> \u6392\u5e8f\u3002<\/p>\n<\/blockquote>\n<h3>\u793a\u4f8b1<\/h3>\n<p>\u8f93\u5165\uff1anums = [-4,-1,0,3,10]<br \/>\n\u8f93\u51fa\uff1a[0,1,9,16,100]<br \/>\n\u89e3\u91ca\uff1a\u5e73\u65b9\u540e\uff0c\u6570\u7ec4\u53d8\u4e3a [16,1,0,9,100]<br \/>\n\u6392\u5e8f\u540e\uff0c\u6570\u7ec4\u53d8\u4e3a [0,1,9,16,100]<\/p>\n<h3>\u793a\u4f8b2<\/h3>\n<p>\u8f93\u5165\uff1anums = [-7,-3,2,3,11]<br \/>\n\u8f93\u51fa\uff1a[4,9,9,49,121]<\/p>\n<h3>\u5206\u6790<\/h3>\n<ol>\n<li>\u4f7f\u7528\u66b4\u529b\u89e3\u6cd5\uff0c\u6328\u4e2a\u5e73\u65b9\u7136\u540e\u904d\u5386<\/li>\n<li>\u4f7f\u7528\u53cc\u6307\u9488\uff0c\u8d1f\u6570\u7684\u5e73\u65b9\u80af\u5b9a\u662f\u6b63\u6570\uff0c\u6bd4\u8f83\u4e24\u7aef\u6570\u5b57\u5e73\u65b9\u540e\u7684\u5927\u5c0f\uff0c\u5012\u5e8f\u63d2\u5165\u8fd4\u56de\u6570\u7ec4<\/li>\n<\/ol>\n<h3>\u5b9e\u73b0<\/h3>\n<ol>\n<li>\u66b4\u529b\u89e3\u6cd5\n<pre><code class=\"language-java\">class Solution {\npublic int[] sortedSquares(int[] nums) {\n    for(int i=0;i&lt;nums.length;i++){\n        nums[i]*=nums[i];\n    }\n    Arrays.sort(nums);\n    return nums;\n}\n}<\/code><\/pre>\n<\/li>\n<li>\u53cc\u6307\u9488\n<pre><code class=\"language-java\">class Solution {\npublic int[] sortedSquares(int[] nums) {\n    int l = 0;\n    int r = nums.length-1;\n    int ans[] = new int[nums.length];\n    for(int i = ans.length-1;i&gt;-1;i--){\n        int left = nums[l]*nums[l];\n        int right = nums[r]*nums[r];\n        if(left&lt;right){\n            ans[i] = right;\n            r--;\n        }else{\n            ans[i] = left;\n            l++;\n        }\n    }\n    return ans;\n}\n}<\/code><\/pre>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>977. \u6709\u5e8f\u6570\u7ec4\u7684\u5e73\u65b9 \u7ed9\u4f60\u4e00\u4e2a\u6309 \u975e\u9012\u51cf\u987a\u5e8f \u6392\u5e8f\u7684\u6574\u6570\u6570\u7ec4 nums\uff0c\u8fd4\u56de \u6bcf\u4e2a\u6570\u5b57\u7684\u5e73\u65b9 \u7ec4\u6210\u7684\u65b0\u6570\u7ec4\uff0c\u8981\u6c42\u4e5f\u6309 \u975e\u9012\u51cf\u987a &#8230;<\/p>","protected":false},"author":1,"featured_media":665,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[58,56],"_links":{"self":[{"href":"https:\/\/bigwer.cn\/index.php\/wp-json\/wp\/v2\/posts\/662"}],"collection":[{"href":"https:\/\/bigwer.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bigwer.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bigwer.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bigwer.cn\/index.php\/wp-json\/wp\/v2\/comments?post=662"}],"version-history":[{"count":3,"href":"https:\/\/bigwer.cn\/index.php\/wp-json\/wp\/v2\/posts\/662\/revisions"}],"predecessor-version":[{"id":666,"href":"https:\/\/bigwer.cn\/index.php\/wp-json\/wp\/v2\/posts\/662\/revisions\/666"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bigwer.cn\/index.php\/wp-json\/wp\/v2\/media\/665"}],"wp:attachment":[{"href":"https:\/\/bigwer.cn\/index.php\/wp-json\/wp\/v2\/media?parent=662"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bigwer.cn\/index.php\/wp-json\/wp\/v2\/categories?post=662"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bigwer.cn\/index.php\/wp-json\/wp\/v2\/tags?post=662"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}