Skip to content

Commit c5a6c3e

Browse files
committed
977.有序数组的平方Go排序法
1 parent 872f0de commit c5a6c3e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

problems/0977.有序数组的平方.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,17 @@ class Solution:
181181
### Go:
182182

183183
```Go
184+
// 排序法
185+
func sortedSquares(nums []int) []int {
186+
for i, val := range nums {
187+
nums[i] *= val
188+
}
189+
sort.Ints(nums)
190+
return nums
191+
}
192+
```
193+
```Go
194+
// 双指针法
184195
func sortedSquares(nums []int) []int {
185196
n := len(nums)
186197
i, j, k := 0, n-1, n-1

0 commit comments

Comments
 (0)