1到10万,里面有一个数字重复了,写一个算法去重,

解决方案 »

  1.   

    int[] nums = {4, 5, 5, 6, 8, 8, 7 };
            List<Integer> numList = new ArrayList<Integer>();
            for (int i : nums)
                numList.add(i);
            Set<Integer> numSet = new HashSet<Integer>();
            numSet.addAll(numList);
            System.out.println(numSet);
      

  2.   

    放进一个set可以吗
      

  3.   

    直接利用hashSet去重
      

  4.   

    hashset 解决
      

  5.   

    对性能要求不高的情况下 ,Set集合就可以,如果考虑性能,可以尝试使用位图算法。
      

  6.   

    特定条件,因为只有一个重复的数字
    考虑能不能先用二叉树排个序,然后
    if(nums[50000] == 50000){
    //重复的数在50000~100000}else{
    //重复的数在0~50000}二分法,递归一下,最多执行17次就能找到这个重复的数字了