数组去重


import java.util.Arrays;

public class Repeat {
    public static void main(String[] args) {
        int[] a = {1,2,3,2,1};
        
        for (int i = 0; i < a.length; i++) {
            for (int j = a.length-1; j > i; j--) {
                if(a[i] == a[j]) {
                    for (int k = j; k < a.length-1; k++) {
                        a[k] = a[k+1];
                    }
                    a = Arrays.copyOf(a, a.length-1);
                }
            }
        }
        for (int i = 0; i < a.length; i++) {
            System.out.println(a[i]);   
        }   
    }
}

你可能感兴趣的:(数组去重)