Skip to content

Commit

Permalink
feat: Add leetcode example on sorting. Level easy
Browse files Browse the repository at this point in the history
  • Loading branch information
VishwajeetVT committed Nov 28, 2024
1 parent af2692d commit 0d39d15
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.practice.dsa.leet_code.easy.sorting;

import java.util.Arrays;

public class SortSquares {
public static void main(String[] args) {
int[] arr = {-4, -1, 0, 3, 10};
System.out.println(Arrays.toString(sortedSquares(arr)));
}

public static int[] sortedSquares(int[] arr) {
int[] result = new int[arr.length];
for (int i = 0; i < arr.length; i++) {
result[i] = arr[i]*arr[i];
}
System.out.println("Squares before sorting:"+Arrays.toString(result));
Arrays.sort(result);
return result;
}
}

0 comments on commit 0d39d15

Please sign in to comment.