Skip to content

Commit 87bf2e6

Browse files
977. Squares of a Sorted Array
Difficulty: Easy 132 / 132 test cases passed. Runtime: 228 ms Memory Usage: 15.1 MB
1 parent 52390cc commit 87bf2e6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Easy/977.SquaresofaSortedArray.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
Given an array of integers A sorted in non-decreasing order, return an
3+
array of the squares of each number, also in sorted non-decreasing order.
4+
5+
Example:
6+
Input: [-4,-1,0,3,10]
7+
Output: [0,1,9,16,100]
8+
"""
9+
#Difficulty: Easy
10+
#132 / 132 test cases passed.
11+
#Runtime: 228 ms
12+
#Memory Usage: 15.1 MB
13+
14+
#Runtime: 228 ms, faster than 78.60% of Python3 online submissions for Squares of a Sorted Array.
15+
#Memory Usage: 15.1 MB, less than 44.05% of Python3 online submissions for Squares of a Sorted Array.
16+
17+
class Solution:
18+
def sortedSquares(self, A: List[int]) -> List[int]:
19+
for i, n in enumerate(A):
20+
A[i] = n**2
21+
A.sort()
22+
return A

0 commit comments

Comments
 (0)