leetcode 1051. Height Checker
Students are asked to stand in non-decreasing order of heights for an annual photo.
Return the minimum number of students not standing in the right positions. (This is the number of students that must move in order for all students to be standing in non-decreasing order of height.)
Example 1:
Input: [1,1,4,2,1,3]
Output: 3
Explanation:
Students with heights 4, 3 and the last 1 are not standing in the right positions.
Note:
1 <= heights.length <= 100
1 <= heights[i] <= 100
简单题。
class Solution {
public:
int heightChecker(vector<int>& heights) {
vector<int> ret(heights);
int wrongNum = ;
sort(ret.begin(), ret.end());
for (int i = ; i < heights.size(); ++i) {
if (heights[i] != ret[i])
++wrongNum;
}
return wrongNum;
}
};
leetcode 1051. Height Checker的更多相关文章
- 【LEETCODE】40、1051. Height Checker
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...
- 【Leetcode_easy】1051. Height Checker
problem 1051. Height Checker solution class Solution { public: int heightChecker(vector<int>&a ...
- 【LeetCode】1051. Height Checker 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序比较 日期 题目地址:https://leetc ...
- 【leetcode】1051. Height Checker
题目如下: Students are asked to stand in non-decreasing order of heights for an annual photo. Return the ...
- LeetCode 1051. 高度检查器(Height Checker) 28
1051. 高度检查器 1051. Height Checker 题目描述 学校在拍年度纪念照时,一般要求学生按照 非递减 的高度顺序排列. 请你返回至少有多少个学生没有站在正确位置数量.该人数指的是 ...
- LeetCode.1051-身高检查器(Height Checker)
这是小川的第390次更新,第420篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第252题(顺位题号是1051).要求学生按身高递增的顺序站列来拍年度照片. 返回没有站在 ...
- [LeetCode] Minimum Height Trees 最小高度树
For a undirected graph with tree characteristics, we can choose any node as the root. The result gra ...
- LeetCode Minimum Height Trees
原题链接在这里:https://leetcode.com/problems/minimum-height-trees/ 题目: For a undirected graph with tree cha ...
- [LeetCode] Strong Password Checker 密码强度检查器
A password is considered strong if below conditions are all met: It has at least 6 characters and at ...
随机推荐
- 20165207 Exp6 信息搜集与漏洞扫描
Exp6 信息搜集与漏洞扫描 一.实验内容 1. 查询基本信息 1.1. 使用whois.nslookup.dig命令查询DNS和ip信息 使用whois查询某个我经常用的学习网站的域名(去掉了前缀的 ...
- Break 和 Continue 标签 kotlin(12)
Break 和 Continue 标签 在 Kotlin 中任何表达式都可以用标签(label ) 来标记. 标签的格式为标识符后跟 @ 符 号,例如: abc@ . fooBar@ 都是有效的标签( ...
- Note 1 for <Pratical Programming : An Introduction to Computer Science Using Python 3>
Book Imformation : <Pratical Programming : An Introduction to Computer Science Using Python 3> ...
- 本地oracle可以通过localhost连接,无法通过ip地址连接解决方法,oracle远程连接配置
Oracle11g安装后只有本地可以连接,远程无法连接,而且本地只能配置成localhost配置成IP地址也无法连接. 这是因为安装oracle的时候没有配置远程的监听,默认的监听是localhost ...
- react native tap切换页面卡顿
问题描述:做一个页面,左边是导航,每次点击一个菜单,右边立即显示出对应的视图,数据会重新过滤,使用setState 更新视图,会卡顿 解决办法: InteractionManager.runAfter ...
- sql输出表中重复数据
数据: 1 1 2 32 2 2 33 1 2 34 2 2 35 2 1 36 1 1 37 3 2 1 表格查询: SELECT * FROM `t1`; 可以看到,如果界定为 a.b.c 都相同 ...
- EPOLL内核原理极简图文解读(转)
预备知识:内核poll钩子原理内核函数poll_wait把当前进程加入到驱动里自定义的等待队列上 当驱动事件就绪后,就可以在驱动里自定义的等待队列上唤醒调用poll的进程 故poll_wait作用:可 ...
- WDS部署Windows server2012初试
通过安装WDS,使用pxe自动部署Windows Server Active Directory详解:https://blog.51cto.com/terryli/141686 1.首先在VM虚拟机上 ...
- Introduction to pointers in C
The basic purpose of developing a C programming tutorial for this website – CircuitsToday – is to ma ...
- 7NiuYun云存储UploadPicture
1.七牛云云存储图片,上传.下载.源代码地址:ssh (git@gitee.com:516877626/QiNiuYunUploadpicture.git) .https(https://gitee. ...