Skip to content

Commit e718d9b

Browse files
Merge pull request youngyangyang04#2517 from markwang1992/master
977.有序数组的平方Go排序法
2 parents 65f5430 + 0b82714 commit e718d9b

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)