Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.

//出现次数超过数组长度一半的元素,排序取出中间位置的元素即可

class Solution {
public:int majorityElement(vector<int>& nums) {if(nums.size()==0)return -1;sort(nums.begin(),nums.end());int mid = nums.size()/2;return nums[mid];}
};

转载于:https://www.cnblogs.com/xiuxiu55/p/6509264.html

169. Majority Element相关推荐

  1. leetcode讲解--169. Majority Element

    169. Majority Element Given an array of size n, find the majority element. The majority element is t ...

  2. [Easy] 169. Majority Element

    169. Majority Element Given an array of size n, find the majority element. The majority element is t ...

  3. [勇者闯LeetCode] 169. Majority Element

    [勇者闯LeetCode] 169. Majority Element Description Given an array of size n, find the majority element. ...

  4. leetcode 169. Majority Element

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  5. 【LeetCode】169. Majority Element

    原题链接:https://leetcode.com/problems/majority-element/description/ 要求: Given an array of size n, find ...

  6. Leetcode - 169. Majority Element (多数投票问题)

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  7. 【LeetCode从零单排】No.169 Majority Element(hashmap用法)

    题目 Given an array of size n, find the majority element. The majority element is the element that app ...

  8. [LeetCode]: 169: Majority Element

    题目: Given an array of size n, find the majority element. The majority element is the element that ap ...

  9. [LeetCode] 169. Majority Element 多数元素

    Given an array of size n, find the majority element. The majority element is the element that appear ...

最新文章

  1. 学界 | 和清华大学自然语言处理与社会人文计算实验室一起读机器翻译论文
  2. 从请求管道深入剖析HttpModule的实现机制,有图有真相
  3. SpringMVC(三)——JSON
  4. centos6.4下安装python3.6以及对应的django1.11
  5. Qt tableWidget导入\导出Excel表格 自用
  6. java程序员应该掌握的技术才算得上熟练Java开发
  7. SD-WAN新价值:中企通信与Fortinet强强联合 安全先行
  8. 正常的vite创建项目并且安装vue router,vant的代码示例
  9. centos选择php7 作为默认版本_树莓派下安装Nginx+Php7.3 搭建Web服务器
  10. 现实迷途 第二十五章 重见故人
  11. 【Unity Shader】---UnityShader 提供的CG/HLSL语义
  12. Win7如何自定义鼠标右键菜单 添加新建文本文档
  13. IO口读写实验微型计算机,微机原理与单片机实验报告.doc
  14. pacman系列命令
  15. oracle中累计求和_oracle累计求和
  16. 住建部发布《全国建筑工人管理服务信息平台数据对接方案》
  17. LaTex 数学之矩阵
  18. perl中正则匹配中文字符
  19. 千锋python培训班课程
  20. 0922Android传感器实例指南针

热门文章

  1. java编写桌球游戏素材小球图片_你学不好Java还是有原因的!拿走这套Java系统教程,自学必备...
  2. eq linux_在线试用 200 多种 Linux 和 Unix 操作系统 | Linux 中国
  3. c语言放空一个数组,C++语言
  4. 汉塔克问题(C语言递归)
  5. 运算符重载(c++细节篇二)
  6. #地形剖面图_高中地理——每日讲1题(地形剖面图)
  7. 百练OJ:2808:校门外的树
  8. 【项目管理】敏捷原则
  9. 国产操作系统UOS —— 你开始使用了吗?这个新年假期我已安装好了!
  10. MapReduce Java API实例-排序