编程之美--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;  
    }  
}  

 

posted @ 2013-04-08 22:52  l851654152  阅读(178)  评论(0编辑  收藏  举报