Skip to content

Latest commit

 

History

History
23 lines (16 loc) · 285 Bytes

squares-of-a-sorted-array.md

File metadata and controls

23 lines (16 loc) · 285 Bytes

Code

func sortedSquares(nums []int) []int {
	sol := []int{}

	for _, num := range nums {
		sol = append(sol, num*num)
	}

	sort.Ints(sol)

	return sol
}

Solution in mind

  • Iterate through array keeping track of squares.

  • Sort array holding squares