Find duplicate element in array in time O(n)

前端 未结 24 2931
余生分开走
余生分开走 2020-11-27 10:07

I have been asked this question in a job interview and I have been wondering about the right answer.

You have an array of numbers from 0 to n-1, one o

24条回答
  •  迷失自我
    2020-11-27 10:57

    This program is based on c# and if you want to do this program using another programming language you have to firstly change an array in accending order and compare the first element to the second element.If it is equal then repeated number found.Program is

    int[] array=new int[]{1,2,3,4,5,6,7,8,9,4};
    Array.Sort(array);
    for(int a=0;a

提交回复
热议问题