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

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

Leetcode 169. Majority Element

2019-11-11 01:06:55
字體:
來源:轉載
供稿:網友

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; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 乃东县| 永城市| 法库县| 双流县| 雅江县| 西畴县| 新乡市| 治县。| 铁力市| 洪湖市| 尉氏县| 中牟县| 嘉义县| 临潭县| 广宁县| 广南县| 礼泉县| 临西县| 珠海市| 夏邑县| 台州市| 丰都县| 黄浦区| 商洛市| 安达市| 义马市| 商南县| 江津市| 左云县| 龙江县| 环江| 封丘县| 崇礼县| 修文县| 昌图县| 汤原县| 延寿县| 洞口县| 平山县| 特克斯县| 东至县|