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 ...
随机推荐
- Ubuntu16.04下安装最新版本的CMake
当前最新版CMake为3.9.1.. Ubuntu中更新cmake到最新版本,过程如下: 1. 卸载已经安装的旧版的CMake[非必需] apt-get autoremove cmake 2. 文 ...
- HearthstoneBot
https://github.com/ChuckFork/HearthstoneBot Sigmund Card game automation framework Hooks game and lo ...
- 【编程漫谈】PHP
PHP是个很古老的脚本技术了,当年CGI比较让人诟病,于是PHP横空出世.PHP即写即用特性,吸引了一大批粉丝,而且类似C语言的编程风格,让那些C程序员非常容易地转到这个平台上来.当然PHP刚出来的时 ...
- leetcode-hard-array-287. Find the Duplicate Number
mycode 77.79% class Solution(object): def findDuplicate(self, nums): """ :type nums ...
- SSH开发中 使用超链接到action 其excute方法会被执行两次 actual row count: 0; expected: 1
由于执行两次excute,所以在做删除操作的时候会出现 Batch update returned unexpected row count from update [0]; actual row c ...
- java和C++之间的调用
java和C++之间的调用其实和C差不多,只是有几点不一样 区别: 包名.类名.h 这个头文件必须有且必须在JNI目录里 后缀不需要修改 /* DO NOT EDIT THIS FILE - it i ...
- Uboot启动分析之Start.S
1.start.S引入 1.1.u-boot.lds中找到start.S入口 1)C语言中代码的分析第一步就是找到main.c,找到函数的入口 2)uboot中因为有汇编语言参与所以就不能像C一样.U ...
- flutter Oops; flutter has exited unexpectedly
使用模拟器时执行flutter run 报出下面一大堆错误 注意只有模拟器有这种问题,真机可以正常运行 Oops; flutter has exited unexpectedly. Sending c ...
- java 抽取 word,pdf 的四种武器
转自:https://www.ibm.com/developerworks/cn/java/l-java-tips/ 感谢作者发布的文章 用 jacob 其实 jacob 是一个 bridag ...
- springboot启动报错:Failed to configure a DataSource
一.背景 springboot的出现,让项目搭建变得更方便快捷,同时简化掉很多的样板化配置代码,提高开发效率. 通过idea生成springboot项目,启动报错:Failed to configur ...