Algorithm: efficient way to remove duplicate integers from an array

前端 未结 30 2238
离开以前
离开以前 2020-11-22 16:03

I got this problem from an interview with Microsoft.

Given an array of random integers, write an algorithm in C that removes duplicated numbers an

30条回答
  •  无人及你
    2020-11-22 16:24

    In JAVA,

        Integer[] arrayInteger = {1,2,3,4,3,2,4,6,7,8,9,9,10};
    
        String value ="";
    
        for(Integer i:arrayInteger)
        {
            if(!value.contains(Integer.toString(i))){
                value +=Integer.toString(i)+",";
            }
    
        }
    
        String[] arraySplitToString = value.split(",");
        Integer[] arrayIntResult = new Integer[arraySplitToString.length];
        for(int i = 0 ; i < arraySplitToString.length ; i++){
            arrayIntResult[i] = Integer.parseInt(arraySplitToString[i]);
        }
    

    output: { 1, 2, 3, 4, 6, 7, 8, 9, 10}

    hope this will help

提交回复
热议问题