题目描述
blablabla
样例
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
import java.util.Scanner;
class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] nums = new int[n];
for (int i = 0; i < n; i++) nums[i] = sc.nextInt();
mergeSort(nums, 0, n - 1, new int[n]);
for (int i : nums) {
System.out.print(i);
System.out.print(‘ ‘);
}
}
public static void mergeSort(int[] nums, int left, int right, int[] temp) {
if (left >= right) return;
int mid = left + (right - left) / 2;
mergeSort(nums, left, mid, temp);
mergeSort(nums, mid + 1, right, temp);
int i = left, j = mid + 1, index = 0;
while (i <= mid || j <= right) {
if (i <= mid && (j > right || nums[i] < nums[j])) {
temp[index++] = nums[i++];
} else {
temp[index++] = nums[j++];
}
}
for (int k = left; k <= right; k++) nums[k] = temp[k - left];
}
}
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
老谜语人了,