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

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

Leetcode 169. Majority Element

2019-11-11 01:44:50
字體:
來源:轉載
供稿:網友

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; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 恩平市| 容城县| 红安县| 察哈| 蓬溪县| 武隆县| 甘孜县| 呈贡县| 茶陵县| 桐庐县| 云浮市| 桐梓县| 迁安市| 陈巴尔虎旗| 荔波县| 来安县| 平原县| 和平县| 荥阳市| 临沭县| 麻城市| 滨州市| 蚌埠市| 米林县| 克山县| 佛学| 高邑县| 泸水县| 屯昌县| 肇东市| 梁河县| 静海县| 泗水县| 惠水县| 荃湾区| 长治县| 阜新| 桐柏县| 富裕县| 拉孜县| 林口县|