Problem
Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.
Example 1:
Input : nums = [-4,-1,0,3,10]
Output : [0,1,9,16,100]
Explanation
- After squaring, the array becomes [16,1,0,9,100].
- After sorting, it becomes [0,1,9,16,100].
Constraints:
- 1 <= nums.length <= 104
- -104 <= nums[i] <= 104
- nums is sorted in non-decreasing order.
solution
class Solution:
def sortedSquares(self, nums: List[int]) -> List[int]:
return sorted([i**2 for i in nums])
'알고리즘 > 기타 알고리즘' 카테고리의 다른 글
[LeetCode] Merge Sorted Array (Python) (0) | 2022.05.22 |
---|---|
[LeetCode] Duplicate Zeros (Python) (0) | 2022.05.16 |
[LeetCode] Find Numbers with Even Number of Digits (Python) (0) | 2022.05.16 |
[LeetCode] Max Consecutive Ones (Python) (0) | 2022.05.16 |
[이것이 코딩 테스트다 with Python] 고정점 찾기 : 이진탐색 (0) | 2022.01.24 |