We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 52390cc commit 87bf2e6Copy full SHA for 87bf2e6
Easy/977.SquaresofaSortedArray.py
@@ -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