编程之美006

 public static int find(int[] array)  
    {  
        int size = array.length;  
        int result = 0;// 需要查找的结果  
        int times = 0;// 出现的次数  
        for (int i = 0; i < size; i++)  
        {  
            // 如果次数等于0,重新指定结果  
            if (times == 0)  
            {  
                result = array[i];  
                times = 1;  
            }  
            else  
            {  
                if (result == array[i])  
                {  
                    ++times;  
                }  
                else  
                {  
                    --times;  
                }  
            }  
        }  
  
        return result;  
    }  
}  
一切源于对计算机的热爱
原文地址:https://www.cnblogs.com/liuweilinlin/p/3009114.html