Advertisement
smj007

Untitled

Mar 9th, 2025
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.41 KB | None | 0 0
  1. class Solution:
  2.     def sortedSquares(self, nums: List[int]) -> List[int]:
  3.  
  4.         result = []
  5.         start = 0
  6.         end = len(nums) - 1
  7.  
  8.         while start<=end:
  9.             if abs(nums[start]) > abs(nums[end]):
  10.                 result.append(nums[start]**2)
  11.                 start += 1
  12.             else:
  13.                 result.append(nums[end]**2)
  14.                 end -= 1
  15.  
  16.         return result[::-1]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement