快速查找

有10000个无序排列的数字(1<=N<=9999),其中有一个重复的数字,设计一个算法快速高效的找到重复数字。

 public class Cacl
    {

        public int GetRepeatNumber(int[] arr)
        {
           while (true)
          {
             int t = arr[0];
             if (arr[t] != t)
            {
               arr[0] = arr[t];
               arr[t] = t;
            }
            else
           {
              return t; 
           }
        }
      }
  }

 

 

 

posted @ 2013-02-26 18:00  Joe·Zhou  阅读(323)  评论(2编辑  收藏  举报