Merge pull request #2517 from markwang1992/master

977.有序数组的平方Go排序法
This commit is contained in:
程序员Carl
2024-05-08 10:24:32 +08:00
committed by GitHub

View File

@ -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