@@ -0,0 +1,585 @@
+package michael.leetcode;%0D%0A%0D%0A/**%0D%0A * Find the number in the array, that the occurrence is more than a half.%0D%0A * @author Michael Wan.%0D%0A *%0D%0A */%0D%0Apublic class FindNOverHalf %7B%0D%0A%0D%0A%09public static void main(String%5B%5D args) %7B%0D%0A%09%09int%5B%5D nums = new int%5B%5D %7B 1, 2, 3, 2, 2, 2, 5, 4, 2 %7D;%0D%0A%09%09System.out.println(findN(nums));%0D%0A%09%7D%0D%0A%0D%0A%09public static int findN(int%5B%5D nums) %7B%0D%0A%09%09int seed = nums%5B0%5D;%0D%0A%09%09int count = 0;%0D%0A%09%09for (int num : nums) %7B%0D%0A%09%09%09if (count == 0) %7B%0D%0A%09%09%09%09seed = num;%0D%0A%09%09%09%09count++;%0D%0A%09%09%09%7D%0D%0A%0D%0A%09%09%09if (seed == num) %7B%0D%0A%09%09%09%09count++;%0D%0A%09%09%09%7D else %7B%0D%0A%09%09%09%09count--;%0D%0A%09%09%09%7D%0D%0A%09%09%7D%0D%0A%09%09return seed;%0D%0A%09%7D%0D%0A%0D%0A%7D%0D%0A

find the number in the array that occurrence is more than a half.