103 判断数组中所有的数字是否只出现一次
Table of Contents

ac

  1. 辅助空间
  2. 排序后判断
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static Scanner sc = new Scanner(System.in);

    public static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i=0;i<n;i++) {
            arr[i] = sc.nextInt();
        }
        boolean flag = false;
        Arrays.sort(arr);
        int lastVal = arr[0];
        for(int i=1;i<n;i++){
            if(arr[i] == lastVal){
                flag = true;
                break;
            }else {
                lastVal = arr[i];
            }
        }
        System.out.println(flag ? "NO" : "YES");
    }

}
/*
 */