新学了一个 treeset 集合

import java.util.Scanner;
import java.util.*;


public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        for(int i=0;i<n;i++){
            TreeSet<Integer> set = new TreeSet<>();
            int k = sc.nextInt();
            for(int j=0; j<k;j++){
                int tmep = sc.nextInt();
                set.add(tmep);
            }
            Object[] arr = set.toArray();
            if(set.size()<3) System.out.println("YES");
            else if(set.size()>3) System.out.println("NO");
            else if((int)arr[0] + (int)arr[2] == 2*(int)arr[1]) System.out.println("YES");
            else System.out.println("NO");
        }

    }
}