去重

作者: 好名字_4d27 | 来源:发表于2022-03-29 18:39 被阅读0次
  public static void main(String[] args) {
        int [] arr = {6,2,13,4,5,2,2,4,4,4};
        int count=arr.length;

        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length; j++) {
                if (arr[i]<arr[j]){
                    arr[i]=arr[i]^arr[j];
                    arr[j]=arr[i]^arr[j];
                    arr[i]=arr[i]^arr[j];
                }
            }
        }

        //2 2 2 4 4 4 4 5 6 13

        //慢指针
        count = 0;
        //快指针
        for (int i = 1; i < arr.length; i++) {
            if (arr[i]!=arr[count]){
                count ++ ;
                arr[count] = arr[i];

            }
        }

        count++;

        for (int x = 0; x < count; x++) {
            System.out.printf(arr[x]+" ");
        }


    }

相关文章

网友评论

      本文标题:去重

      本文链接:https://www.haomeiwen.com/subject/ezmfjctx.html