mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 03:33:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			23 lines
		
	
	
		
			880 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			23 lines
		
	
	
		
			880 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>Given an array <code>nums</code> of size <code>n</code>, return <em>the majority element</em>.</p>
 | 
						|
 | 
						|
<p>The majority element is the element that appears more than <code>⌊n / 2⌋</code> times. You may assume that the majority element always exists in the array.</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Example 1:</strong></p>
 | 
						|
<pre><strong>Input:</strong> nums = [3,2,3]
 | 
						|
<strong>Output:</strong> 3
 | 
						|
</pre><p><strong>Example 2:</strong></p>
 | 
						|
<pre><strong>Input:</strong> nums = [2,2,1,1,1,2,2]
 | 
						|
<strong>Output:</strong> 2
 | 
						|
</pre>
 | 
						|
<p> </p>
 | 
						|
<p><strong>Constraints:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><code>n == nums.length</code></li>
 | 
						|
	<li><code>1 <= n <= 5 * 10<sup>4</sup></code></li>
 | 
						|
	<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>
 | 
						|
</ul>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<strong>Follow-up:</strong> Could you solve the problem in linear time and in <code>O(1)</code> space? |