977. Squares of a Sorted Array
🟩 Easy
Question
Given an array of integers A
sorted in non-decreasing order, return an array of the squares of each number, also in sorted non-decreasing order.
Examples:
Note:
1 <= A.length <= 10000
-10000 <= A[i] <= 10000
A
is sorted in non-decreasing order.
Two Pointer Approach
Time complexity: O(n)
Space complexity: O(n)
Sort
Time complexity: O(n log n)
Space complexity: O(n)
Last updated
Was this helpful?