Skip to content

Commit 0064c6a

Browse files
authored
Create SortedSquaredArray.java
1 parent bd4ebef commit 0064c6a

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) Jul 2, 2015 CareerMonk Publications and others.
2+
* E-Mail : info@careermonk.com
3+
* Creation Date : 2015-01-10 06:15:46
4+
* Last modification : 2006-05-31
5+
by : Narasimha Karumanchi
6+
* File Name : ConvertArraytoSawToothWave.java
7+
* Book Title : Data Structures And Algorithms Made In Java
8+
* Warranty : This software is provided "as is" without any
9+
* warranty; without even the implied warranty of
10+
* merchantability or fitness for a particular purpose.
11+
*
12+
*/
13+
14+
package chapter10sorting;
15+
16+
class SortedSquaredArray {
17+
public int[] sortedSquaredArray(int[] A) {
18+
int n = A.length;
19+
int[] result = new int[n];
20+
for (int i = 0; i < n; ++i)
21+
result[i] = A[i] * A[i];
22+
23+
Arrays.sort(result);
24+
return result;
25+
}
26+
}

0 commit comments

Comments
 (0)