Skip to content

Commit 8f1b2be

Browse files
authored
Create Create SortedSquaredArray.py
1 parent ccbf8a7 commit 8f1b2be

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright (c) Dec 22, 2014 CareerMonk Publications and others.
2+
# E-Mail : [email protected]
3+
# Creation Date : 2014-01-10 06:15:46
4+
# Last modification : 2008-10-31
5+
# by : Narasimha Karumanchi
6+
# Book Title : Data Structures And Algorithmic Thinking With Python
7+
# Warranty : This software is provided "as is" without any
8+
# warranty; without even the implied warranty of
9+
# merchantability or fitness for a particular purpose.
10+
11+
def sortedSquaredArray(A):
12+
result = []
13+
for i in range(len(A)):
14+
result.append(A[i]*A[i])
15+
result.sort()
16+
return result
17+
18+
A = [-6, -4, 1, 2, 3, 5]
19+
print sortedSquaredArray(A)
20+
21+
#Second approach
22+
def sortedSquaredArray(A):
23+
return sorted([i**2 for i in A])
24+
25+
A = [-6, -4, 1, 2, 3, 5]
26+
print sortedSquaredArray(A)

0 commit comments

Comments
 (0)