【洛谷】P1469 - 找筷子

//效率不通过
public class Main {
    static int N ;
    static int[] arr ;
    
    static HashSet set = new HashSet();
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        N = sc.nextInt();
        
        arr = new int[N];
        
        for (int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }
        
        Arrays.sort(arr);
        
        for (int i = 0; i < N; i++) {
            if (set.contains(arr[i])) {
                set.remove(arr[i]);
            }else {
                set.add(arr[i]);
            }
            
        }
        
        for(Object o : set) {
            System.out.println(o);
        }
        
        sc.close();
            
    }

}

public class Main {
    public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int res = 0;
    for (int i = 0; i < n; i++) {
        res = res ^ s.nextInt();
    }
    System.out.println(res);
    s.close();
}}
public class Main{
    
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int a[]=new int[10000001];
        int num;
        int n=sc.nextInt();
        for (int i = 0; i < n; i++) {
            num=sc.nextInt();
            a[num]++;
        }
        for (int i = 0; i < 10000001; i++) {
            if(a[i]%2==1){
                System.out.println(i);
                break;
            }
        }
        sc.close();
    }
    
    
}

你可能感兴趣的:(【洛谷】P1469 - 找筷子)