Skip to content

Commit 95a9783

Browse files
authored
Update SortedSquares.java
1 parent f8db2fb commit 95a9783

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

LeetCode/SortedSquares.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,36 @@
11

2-
// Java program to Sort square of the numbers
2+
// Java program to Sort the square of the numbers
33
// of the array
44
import java.util.*;
55
import java.io.*;
6-
76
public class sortsq
87
{
98
// Function to sort an square array
109
public static void sortSquares(int arr[])
1110
{
1211
int n = arr.length;
13-
1412
// First convert each array elements
1513
// into its square
1614
for (int i = 0 ; i < n ; i++)
1715
arr[i] = arr[i] * arr[i];
1816

19-
// Sort an array using "inbuild sort function"
17+
// using "inbuild sort function" for sorting
2018
// in Arrays class.
2119
Arrays.sort(arr);
22-
}
23-
24-
// Driver program to test above function
20+
}
21+
//sample driver program
2522
public static void main (String[] args)
2623
{
27-
int arr[] = { -6 , -3 , -1 , 2 , 4 , 5 };
24+
int arr[] = { -17 , -12 , -1 , 4 , 8 , 15 };
2825
int n = arr.length;
2926

30-
System.out.println("Before sort ");
27+
System.out.println("Original ");
3128
for (int i = 0; i < n; i++)
3229
System.out.print(arr[i] + " ");
3330

3431
sortSquares(arr);
3532
System.out.println("");
36-
System.out.println("After Sort ");
33+
System.out.println("Implementing sort");
3734
for (int i = 0 ; i < n ; i++)
3835
System.out.print(arr[i] + " ");
3936

0 commit comments

Comments
 (0)