관리 메뉴

솜씨좋은장씨

[leetCode] 977. Squares of a Sorted Array (Python) 본문

Programming/코딩 1일 1문제

[leetCode] 977. Squares of a Sorted Array (Python)

솜씨좋은장씨 2020. 9. 1. 22:41
728x90
반응형

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.

 

Example 1:

Input: [-4,-1,0,3,10]
Output: [0,1,9,16,100]

Example 2:

Input: [-7,-3,2,3,11]
Output: [4,9,9,49,121]

Note:

  1. 1 <= A.length <= 10000
  2. -10000 <= A[i] <= 10000
  3. A is sorted in non-decreasing order.

Solution 

class Solution:
    def sortedSquares(self, A: List[int]) -> List[int]:
        sqrt_list = [pow(num, 2) for num in A]
        
        answer = sorted(sqrt_list)
        
        return answer

 

 

SOMJANG/CODINGTEST_PRACTICE

1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.

github.com

 

Comments