(nums []int)
| 8 | } |
| 9 | |
| 10 | func sortedSquares(nums []int) []int { |
| 11 | l := len(nums) |
| 12 | ret := make([]int, l) |
| 13 | i, j, k := 0, l-1, l-1 |
| 14 | for i <= j { |
| 15 | if modInt(nums[i]) < modInt(nums[j]) { |
| 16 | ret[k] = nums[j] * nums[j] |
| 17 | j-- |
| 18 | } else { |
| 19 | ret[k] = nums[i] * nums[i] |
| 20 | i++ |
| 21 | } |
| 22 | k-- |
| 23 | } |
| 24 | return ret |
| 25 | } |
| 26 | |
| 27 | func modInt(a int) int { |
| 28 | if a < 0 { |