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 ...
随机推荐
- 6 Java Shell排序
希尔排序是先将整个待排序的记录序列分割成为若干子序列分别进行直接插入排序,待整个序列中的记录“基本有序”时,再对全体记录进行依次直接插入排序. 1.基本思想 将待排序数组按照步长gap进行分组,然后将 ...
- How to intercept any postback in a page? - ASP.NET
How to intercept any postback in a page? - ASP.NET There's a couple of things you can do to intercep ...
- python中列表的简单用法
1.定义list >>> li = ["a", "b", "mpilgrim", "z", " ...
- 数据库开源框架之litepal
主页: [https://github.com/LitePalFramework/LitePal](https://github.com/LitePalFramework/LitePal) 中文文档地 ...
- 从 ssh private key 中重新生成 public key
Use the -y option to ssh-keygen: ssh-keygen -f ~/.ssh/id_rsa -y > ~/.ssh/id_rsa.pub From the 'man ...
- 强大的BeautifulSoup
Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库·它能够通过你喜欢的转换器实现惯用的文档导航 安装BeautifulSoup 推荐使用Beautiful Sou ...
- C# 实现opc ua服务器的远程连接(转)
原文转自:https://www.cnblogs.com/dathlin/p/7724834.html OPC UA简介 OPC是应用于工业通信的,在windows环境的下一种通讯技术,原有的通信技术 ...
- beego 如何自定error
beego通过Redirect方法来进行跳转: 1 2 3 func (this *AddController) Get() { this.Redirect("/", 30 ...
- JobHandle和依赖项
要当您调用作业的Schedule方法时,它将返回JobHandle.您可以在代码中使用一个JobHandle作为其他作业的依赖项.如果作业取决于另一个作业的结果,您可以将第一个作业JobHandle作 ...
- java去除数组中的空值
public String[] deleteArrayNull(String []string) { String []array = string; // 声明一个list List<Stri ...