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

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

Leetcode 169. Majority Element

2019-11-11 02:58:53
字體:
來源:轉載
供稿:網友

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; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 博罗县| 台中市| 青铜峡市| 甘南县| 仲巴县| 咸阳市| 麟游县| 永定县| 曲阳县| 新兴县| 高清| 汾阳市| 乐至县| 乐至县| 绥宁县| 高雄县| 怀宁县| 云和县| 桃园县| 毕节市| 南陵县| 东乌珠穆沁旗| 四子王旗| 托克托县| 高清| 牙克石市| 漳平市| 沂水县| 洛隆县| 安平县| 灯塔市| 民权县| 莆田市| 九江县| 综艺| 佛山市| 苗栗县| 新平| 宝应县| 乌拉特后旗| 华宁县|