中文版: 主要元素
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.
You may assume that the array is non-empty and the majority element always exist in the array.
常规做法
1 |
|
时间复杂度为O(n), 引入了一个map,空间复杂度为O(n)
进阶做法
你有办法在时间复杂度为 O(N),空间复杂度为 O(1) 内完成吗?
1 |
原文链接: https://dashen.tech/2015/03/01/leetcode-169-主要元素/
版权声明: 转载请注明出处.