MCPcopy Create free account
hub / github.com/VanjaRo/LeetCode / sortedSquares

Function sortedSquares

tasks/977.go:10–25  ·  view source on GitHub ↗
(nums []int)

Source from the content-addressed store, hash-verified

8}
9
10func 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
27func modInt(a int) int {
28 if a < 0 {

Callers 1

mainFunction · 0.85

Calls 1

modIntFunction · 0.85

Tested by

no test coverage detected