From c5a6c3e4104bb7a17a55edc44db6cbf7c55e642e Mon Sep 17 00:00:00 2001 From: markwang Date: Mon, 8 Apr 2024 17:12:03 +0800 Subject: [PATCH] =?UTF-8?q?977.=E6=9C=89=E5=BA=8F=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E7=9A=84=E5=B9=B3=E6=96=B9Go=E6=8E=92=E5=BA=8F=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0977.有序数组的平方.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/problems/0977.有序数组的平方.md b/problems/0977.有序数组的平方.md index 5bdbcbc7..a39902b3 100644 --- a/problems/0977.有序数组的平方.md +++ b/problems/0977.有序数组的平方.md @@ -181,6 +181,17 @@ class Solution: ### Go: ```Go +// 排序法 +func sortedSquares(nums []int) []int { + for i, val := range nums { + nums[i] *= val + } + sort.Ints(nums) + return nums +} +``` +```Go +// 双指针法 func sortedSquares(nums []int) []int { n := len(nums) i, j, k := 0, n-1, n-1