1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/主要元素 [find-majority-element-lcci].html
2022-03-29 12:43:11 +08:00

22 lines
652 B
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>数组中占比超过一半的元素称之为主要元素。给你一个<strong> 整数 </strong>数组,找出其中的主要元素。若没有,返回 <code>-1</code> 。请设计时间复杂度为 <code>O(N)</code> 、空间复杂度为 <code>O(1)</code> 的解决方案。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>[1,2,5,9,5,9,5,5,5]
<strong>输出:</strong>5</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>[3,2]
<strong>输出:</strong>-1</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>[2,2,1,1,1,2,2]
<strong>输出:</strong>2</pre>