文章来源地址https://www.toymoban.com/news/detail-614099.html
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
int[] arr = new int[N];
for (int i = 0; i < N; i++) {
int n = scan.nextInt();
arr[i] = n;
}
int count = getSortArr(arr);
int i = 0;
while (i < count) {
System.out.println(arr[i]);
i++;
}
}
public static int getSortArr(int[]src) {
//插入排序
for (int i = 1; i < src.length; i++) {
int temp = src[i];
int j = 0;
for (j = i - 1; j >= 0 && temp < src[j]; j--) {
src[j + 1] = src[j];
}
src[j + 1] = temp;
}
//双指针去重
int slow = 0, fast = 1;
while (slow < fast && fast < src.length) {
if (src[slow] == src[fast]) {
fast++;
continue;
}
slow++;
src[slow] = src[fast];
fast++;
}
return slow + 1;//有效长度
}
}
文章来源:https://www.toymoban.com/news/detail-614099.html
到了这里,关于华为刷题:HJ3明明随机数的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!