天天看点

[LeetCode] Majority Element 求众数

Given an array of size n, find the majority element. The majority element is the element that appears more than <code>⌊ n/2 ⌋</code> times.

You may assume that the array is non-empty and the majority element always exist in the array.

Credits:

C++ 解法一:

Java 解法一:

C++ 解法二:

Java 解法二: