File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Copyright (c) Dec 22, 2014 CareerMonk Publications and others.
2
+
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 )
You can’t perform that action at this time.
0 commit comments