October 10, 2014

One Algorithm per day (C#): Find the first repeating element in an array of integers

int[] Arr= {1, 2, 3, 7, 8, 9, 10, 11, 3, 7, 13};

int i = 0;
while(i < Arr.Count()){
 for(int j = i + 1; j < Arr.Count(); j++){
  if(Arr[i] == Arr[j]){
   Console.WriteLine(Arr[i]);
   i = Arr.Count();
   break;
  }
 }
 i++;
}

No comments: