当前位置:网站首页>Lc: sword finger offer 39. numbers that appear more than half of the time in the array
Lc: sword finger offer 39. numbers that appear more than half of the time in the array
2022-07-23 08:18:00 【Seven percent】
There is a number in an array that appears more than half the length of the array , Please find out the number .
You can assume that the array is not empty , And there are always many elements in a given array .
Example 1:
Input : [1, 2, 3, 2, 2, 2, 5, 4, 2]
Output : 2
Method : The number that is more than half must be in the middle of the array after sorting .( Double loop traversal to start with o(╥﹏╥)o)
class Solution {
public int majorityElement(int[] nums) {
Arrays.sort(nums);
return nums[nums.length/2];
}
}边栏推荐
- [reading notes > statistics] 12-01 construction of confidence interval - Introduction to the concept of confidence interval
- mysql使用sql语句查询某个字段值除10等于0的所有数据
- 二叉树(学习日常)
- js 正则删除span标签以及标签里面的内容
- How to use selenium.chrome to realize the extended function of intercepting or forwarding requests
- 学会这些Sketchup技巧,工作效率提高一半
- Leetcode day 26
- pip更新一个package
- JS regular delete the span tag and the content in the tag
- TextView展示不完的内容实现--全显示、部分显示
猜你喜欢

论文阅读:The Perfect Match: 3D Point Cloud Matching with Smoothed Densities

Spark troubleshooting -precondition eof: no length prefix available

深度解析kube-scheduler调度上下文

技术干货 | 基于MindSpore详解Perplexity语言模型评价指标

动作捕捉在自动化控制领域的应用

第三章 栈

C语言函数(1)

Learn these SketchUp skills and improve work efficiency by half

How to use C language to realize simple employee information management system

SQL报错盲注实例分析
随机推荐
读书笔记->统计学】12-02 置信区间的构建-t分布概念简介
flink使用ListState实现KeyedState
c语言扫雷
How to use C language to realize simple employee information management system
三种缓存策略:Cache Aside 策略、Read/Write Through 策略、Write Back 策略
C语言中的字符串
来,滑动到下一个小姐姐
改变this指向了解一下
Redis 配置文件
轻松带你走进turtle绘图的大门
C语言函数(1)
阿里云国际版注册成功后添加支付方式
Redis中的数据类型
QT 线程退出的几种方式
volatile有什么用
Jedis操作Redis
1.10 API and string
21 -- product of arrays other than itself
promise(二)
RPC-BDY(5)-服务自动注销、负载均衡