Skip to content

Commit c2b66c8

Browse files
committed
Adding Efficient Solution Problem - 977 - Squares Sorted Array
1 parent 4729c6a commit c2b66c8

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
##==================================
2+
## Leetcode
3+
## Student: Vandit Jyotindra Gajjar
4+
## Year: 2020
5+
## Problem: 977
6+
## Problem Name: Squares of a Sorted Array
7+
##===================================
8+
#
9+
#Given an array of integers A sorted in non-decreasing order,
10+
#return an array of the squares of each number, also in sorted non-decreasing order.
11+
#
12+
#Example 1:
13+
#
14+
#Input: [-4,-1,0,3,10]
15+
#Output: [0,1,9,16,100]
16+
#Example 2:
17+
#
18+
#Input: [-7,-3,2,3,11]
19+
#Output: [4,9,9,49,121]
20+
class Solution:
21+
def sortedSquares(self, A):
22+
for i in range(len(A)): #Loop through A
23+
A[i] = A[i]*A[i] #Update the list by taking elements square
24+
A.sort() #Sort the A list
25+
return A #We return A

0 commit comments

Comments
 (0)