昨晚的笔试,第二题只过了40%,看了其他人好像是注释中的写法,问问这两种有什么区别呢,我试了好久结果都一样public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 int n = in.nextInt(); int m = in.nextInt(); int k = in.nextInt(); int[] arr = new int[n]; for(int i = 0; i arr[i] = in.nextInt(); } Arrays.sort(arr); int count = 0; for(int i = 0; i for(int j = 1; j if(i + j >= n || arr[i + j] > arr[i] + k){ count++; break; } } } /*int count = n; for(int i = 0; i int next = i + m - 1; if(next >= n) break; if(arr[next] - arr[i] count--; } }*/ System.out.println(count);