Skip to content

Latest commit

 

History

History
43 lines (30 loc) · 1.02 KB

_977. Squares of a Sorted Array.md

File metadata and controls

43 lines (30 loc) · 1.02 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : June 21, 2024

Last updated : June 21, 2024


Related Topics : Array, Two Pointers, Sorting

Acceptance Rate : 72.96 %


Solutions

Python

class Solution:
    def sortedSquares(self, nums: List[int]) -> List[int]:
        output = [0] * len(nums)

        left, right = 0, len(nums) - 1

        for i in range(len(output) - 1, -1, -1) :
            if abs(nums[left]) > abs(nums[right]) :
                output[i] = nums[left] ** 2
                left += 1
            else :
                output[i] = nums[right] ** 2
                right -= 1

        return output