国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Leetcode 169. Majority Element

2019-11-11 01:48:10
字體:
來源:轉載
供稿:網友

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.

s思路: 1. 有一個很著名的算法專門干這個的。 2. 明天思考一下,這個方法為啥行?

class Solution {public: int majorityElement(vector<int>& nums) { // int count=0; int mj=0; for(int num:nums){ if(count==0) mj=num; if(num==mj) count++; else count--; } return mj; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 鹿泉市| 永城市| 金川县| 徐水县| 夏津县| 略阳县| 绍兴市| 南郑县| 庄浪县| 宁津县| 洛浦县| 丰县| 临江市| 广西| 石台县| 高密市| 利川市| 隆回县| 湘潭县| 庆安县| 凤阳县| 当雄县| 三门县| 江安县| 镇安县| 松溪县| 梁平县| 南皮县| 泰兴市| 泾源县| 法库县| 吴江市| 麦盖提县| 乃东县| 布尔津县| 安塞县| 嘉义县| 寻甸| 宣化县| 台安县| 巴林右旗|