C++编程之美-数字之魅(代码清单2-8)

代码清单2-8

Type Find(Type* ID, int N)
{
     Type candidate;
     int nTimes, i;
     for(i = nTimes = 0; i < N; i++)
     {
          if(nTimes == 0)
          {
               candidate = ID[i], nTimes = 1;
          }
          else
          {
               if(candidate == ID[i])
                    nTimes++;
               else
                    nTimes--;
          }
     }
     return candidate; 
}
发布了1210 篇原创文章 · 获赞 951 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/weixin_42528266/article/details/104027419