/**
* @param {number[]} nums
* @return {number[]}
*/
var majorityElement = function(nums) {
nums.sort();
// console.log(nums)
let len = nums.length;
if(!len){
return []
}
let pointer = -1;
let counter = 0;
是let last = nums[0];
let res = []
while(++pointer < len){
if(nums[pointer] === last){
counter++
} else {
if(counter > len / 3){
res.push(last)
}
counter = 1
last = nums[pointer]
}
}
if(counter > len / 3){
res.push(last)
}
return res
};
複製程式碼
Leetcode 229 JavaScript
相關文章
- ABC229 覆盤
- Benefits of Index-Organized Tables (229)IndexZed
- Leetcode 921 JavascriptLeetCodeJavaScript
- Leetcode #463 JavascriptLeetCodeJavaScript
- Leetcode # 495 JavascriptLeetCodeJavaScript
- Leetcode 513 javascriptLeetCodeJavaScript
- LeetCode 747 JavaScriptLeetCodeJavaScript
- LeetCode 799 JavaScriptLeetCodeJavaScript
- LeetCode 162 JavascriptLeetCodeJavaScript
- LeetCode #378 JavaScriptLeetCodeJavaScript
- LeetCode 70題 爬樓梯 -- JavaScriptLeetCodeJavaScript
- LeetCode 存在重複元素之JavaScriptLeetCodeJavaScript
- Codeforces Round #229 (Div. 2)(C,E待續)
- Oracle 11G OCP 1Z0-053 229Oracle
- LeetCode7.整數反轉 JavaScriptLeetCodeJavaScript
- Leetcode 685. Redundant Connection II JavascriptLeetCodeJavaScript
- LeetCode刷題(javascript,python3)LeetCodeJavaScriptPython
- Leetcode之javascript解題(No33-34)LeetCodeJavaScript
- 機器學習-cs229-線性迴歸-泰勒展開法機器學習
- Oracle OCP 1Z0 053 Q229(SecureFile LOB)Oracle
- Leetcode 611 javascript Valid Triangle NumberLeetCodeJavaScript
- 源自史丹佛CS229,機器學習備忘錄在集結機器學習
- LeetCode 695. Max Area of Island javascript解決方案LeetCodeJavaScript
- Atitit.atiInputMethod v2詞庫清理策略工具 q229
- 找到好工作之 LeetcodeTop100(Easy) by JavaScriptLeetCodeJavaScript
- 用 JavaScript 刷 LeetCode 的正確姿勢【進階】JavaScriptLeetCode
- Leetcode javascript 3 longest-substring-without-repeating-charactersLeetCodeJavaScript
- Leetcode 202 Happy Number Javascript 解決方案LeetCodeAPPJavaScript
- LeetCode 之 JavaScript 解答第一題 —— 兩數之和(Two Sum)LeetCodeJavaScript
- PostgreSQL 原始碼解讀(229)- Linux Kernel(程式虛擬記憶體#3)SQL原始碼Linux記憶體
- 科技愛好者週刊(第 229 期):手機充電問題的解決
- 小米電動牙刷釋出:充一次電可用25天? 售價229元
- LeetCode 之 JavaScript 解答第169題 —— 求眾數 I(Majority Element)LeetCodeJavaScript
- LeetCode 之 JavaScript 解答第69題 —— X 的平方根(Squrt(x))LeetCodeJavaScript
- LeetCode 之 JavaScript 解答第20題 —— 有效的括號(Valid Parentheses)LeetCodeJavaScript
- LeetCode演算法簡單題--JavaScript(每天一道題)LeetCode演算法JavaScript
- 吳恩達的 CS229,有人把它濃縮成 6 張中文速查表!吳恩達
- 【Leetcode 346/700】79. 單詞搜尋 【中等】【回溯深度搜尋JavaScript版】LeetCodeJavaScript