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 ...
随机推荐
- OUC_Summer Training_ DIV2_#9 719
其实自己只会做很简单的题,有时都不想写解题报告,觉得不值得一写,但是又想到今后也许就不会做ACM了,能留下来的东西只有解题报告了,所以要好好写,很渣的题也要写,是今后的纪念. B - B Time L ...
- python:BeautifulSoup学习
上一篇说到用BeautifulSoup解析源代码,下面我们就来实战一下: from bs4 import BeautifulSoup html = urllib.request.urlopen('ht ...
- 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 ...
- C++ string与int的互相转换
原文地址 C++本身就提供了字符串与整型数之间的互换,那就是利用stringstream.下面是使用方法: 核心: 利用C++中的stringstream流. 由于使用过程比较简单就不再赘述,直接给出 ...
- shell案例(6):1、创建用户 2、创建目录 3、创建文件 4、退出
脚本基本要求 1.创建用户2.创建目录3.创建文件4.退出 #!/bin/bash #author:zhiping.wang Check_error() { ] then echo "$1 ...
- 加密算法之 MD5算法
题记:本人自测了很多次,该算法和apache的commons utils包中的MD5算法计算一致 一.针对文件内容生成MD5值 应用场景:针对文件,在传输过程由于网络原因丢帧或者被人别恶意篡改内容,可 ...
- mariadb数据库(3)连接查询,视图,事务,索引,外键(优化)
--创建学生表 create table students ( id int unsigned not null auto_increment primary key, name varchar(20 ...
- Tomcat远程调试参数
Linux: 关闭防火墙 vim catalina.sh export CATALINA_OPTS="-server -Xdebug -Xnoagent -Djava.compiler=NO ...
- 第一个简单APP设计图
以下是我画出来的最简单的手机UI设计图哟,以后慢慢积累吧.... 其实使用很简单,很多控件都有,直接使用就好....还是多动手吧,相信自己之后能很好的掌握这个的使用哟!!!!!!
- 【AMAD】dramatiq -- Python3实现的一个快速的,可信赖的分布式任务处理库
简介 动机 作用 用法 热度分析 个人评分 简介 Python3实现的一个快速的,可信赖的分布式任务处理库. 动机 dramatq1的官网2写道: Dramatiq成为现实的主要原因是,我想要一个简单 ...