Skip to content

Commit be6515c

Browse files
Time: 319 ms (51.99%), Space: 16.2 MB (72.18%) - LeetHub
1 parent 9dd214b commit be6515c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution:
2+
def sortedSquares(self, nums: List[int]) -> List[int]:
3+
left = 0
4+
counter = right = len(nums) - 1
5+
output = [0] * len(nums)
6+
7+
while left <= right:
8+
9+
if nums[left] * nums[left] > nums[right] * nums[right]:
10+
output[counter] = nums[left] * nums[left]
11+
left += 1
12+
13+
else:
14+
output[counter] = nums[right] * nums[right]
15+
right -= 1
16+
17+
counter -= 1
18+
19+
20+
return output

0 commit comments

Comments
 (0)