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 <= 1001 <= 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 ...
随机推荐
- Python 之 try...except...错误捕捉
Python常见异常类型大概分为以下类: 1.AssertionError:当assert断言条件为假的时候抛出的异常 2.AttributeError:当访问的对象属性不存在的时候抛出的异常 3.I ...
- Python 读文件:IOError: [Errno 0] Error
Windows系统下,这种情况发生在读取文件,再写入过程中出现. 原因是读完文件后python不知道当前文件位置在哪里. 方法一是:在关闭文件前只做读或者写一种操作. 方法二是:在写入文件前使用fil ...
- 前端单点登录(SSO)实现方法(二级域名与主域名)
1.单点登录介绍 单点登录 SSO 全称 Singn Sign On .SSO 是指在多个应用系统中,用户只需要登录一次用户系统,就可以访问其他互相信任的应用系统.例如:在网易官网登录账户,那么再进入 ...
- Warning: setcookie() expects parameter 3 to be long, string given
Warning: setcookie() expects parameter 3 to be long, string given 这个是我用php7.0会报这个错误, 切换低版本php5.6就ok
- 取得远端相应Json并转化为Java对象一
JDK:1.8.0_212 IDE:STS4(Spring Tool Suit4 Version: 4.3.2.RELEASE) 工程下载:https://files.cnblogs.com/file ...
- DP&图论 DAY 6 下午 考试
DP&图论 DAY 6 下午 考试 样例输入 样例输出 题解 >50 pt dij 跑暴力 (Floyd太慢了QWQ O(n^3)) 枚举每个点作为起点,dijks ...
- js window事件解析(转载)
js-window对象的方法和属性资料 hxpd 发表于 2007-05-08 21:58:18 熟练window对象的open.close.alert.confirm.prompt.setTimeo ...
- javascript的变量声明和数据类型
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 阶段3 3.SpringMVC·_04.SpringMVC返回值类型及响应数据类型_1 搭建环境
创建项目 使用骨架,创建webapp 为了创建项目更快速maven设置 archetypeCatalog internal 修改编译的版本 从昨天的课程内复制 相关的坐标.上面是版本锁定. 复制前端的 ...
- Apache POI读取Excel
1.pom.xml配置文件 <!-- 配置Apache POI --> <dependency> <groupId>org.apache.poi</group ...