思路:
我的想法是直接暴力骗分,直接调用函数库的排序方法。Arrays.sort(int[] arr, int start, int end),arr是需要排序的数组,start-end是排序的范围,包括start但不包括end,即排序的索引范围是start-end-1。
Arrays.sort(int[] arr, int start, int end, Collections.reverseOrder()),加入Collections.reverseOrder()参数后就可以实现倒序排列。
然后去测试会发现超时,正确60%,应该是排序函数的复杂度有点高,然后有些兴趣的可以参考这个正解。
我的暴力代码:
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(); // 接收n和m
int m = sc.nextInt();
Integer[] nums = new Integer[n+1];
for (int i=1;i


