fork download
  1. public class Solution {
  2.  
  3. public static void mergeSort(int[] arr, int l, int r){
  4.  
  5. if (l >= r)
  6. return;
  7.  
  8. int mid = (l + r) / 2;
  9.  
  10. mergeSort(arr, l, mid);
  11.  
  12. mergeSort(arr, mid+1, r);
  13.  
  14. merge(arr, l, r);
  15. }
  16.  
  17.  
  18. public static void merge(int[] arr, int l, int r) {
  19.  
  20. int mid = (l + r) / 2;
  21.  
  22. int temp[] = new int[r-l+1];
  23.  
  24. int i = l;
  25. int j = mid+1;
  26.  
  27. int k = 0;
  28.  
  29. while (i <= mid && j <= r) {
  30.  
  31. if (arr[i] < arr[j]) {
  32.  
  33. temp[k] = arr[i];
  34. k++;
  35. i++;
  36. }
  37.  
  38. else {
  39.  
  40. temp[k] = arr[j];
  41. j++;
  42. k++;
  43. }
  44. }
  45.  
  46. while (i <= mid) {
  47.  
  48. temp[k] = arr[i];
  49. k++;
  50. i++;
  51. }
  52.  
  53. while (j <= r) {
  54.  
  55. temp[k] = arr[j];
  56. j++;
  57. k++;
  58. }
  59.  
  60.  
  61. for (int t = 0; t < temp.length; t++) {
  62.  
  63. arr[t + l] = temp[t];
  64. }
  65. }
  66. }
  67.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class Solution is public, should be declared in a file named Solution.java
public class Solution {
       ^
1 error
stdout
Standard output is empty