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. 1 <= heights.length <= 100
  2. 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的更多相关文章

  1. 【LEETCODE】40、1051. Height Checker

    package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...

  2. 【Leetcode_easy】1051. Height Checker

    problem 1051. Height Checker solution class Solution { public: int heightChecker(vector<int>&a ...

  3. 【LeetCode】1051. Height Checker 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序比较 日期 题目地址:https://leetc ...

  4. 【leetcode】1051. Height Checker

    题目如下: Students are asked to stand in non-decreasing order of heights for an annual photo. Return the ...

  5. LeetCode 1051. 高度检查器(Height Checker) 28

    1051. 高度检查器 1051. Height Checker 题目描述 学校在拍年度纪念照时,一般要求学生按照 非递减 的高度顺序排列. 请你返回至少有多少个学生没有站在正确位置数量.该人数指的是 ...

  6. LeetCode.1051-身高检查器(Height Checker)

    这是小川的第390次更新,第420篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第252题(顺位题号是1051).要求学生按身高递增的顺序站列来拍年度照片. 返回没有站在 ...

  7. [LeetCode] Minimum Height Trees 最小高度树

    For a undirected graph with tree characteristics, we can choose any node as the root. The result gra ...

  8. LeetCode Minimum Height Trees

    原题链接在这里:https://leetcode.com/problems/minimum-height-trees/ 题目: For a undirected graph with tree cha ...

  9. [LeetCode] Strong Password Checker 密码强度检查器

    A password is considered strong if below conditions are all met: It has at least 6 characters and at ...

随机推荐

  1. 搞清楚MySQL事务隔离级别

    首先创建一个表 account.创建表的过程略过(由于 InnoDB 存储引擎支持事务,所以将表的存储引擎设置为 InnoDB).表的结构如下: 然后往表中插入两条数据,插入后结果如下: 为了说明问题 ...

  2. FastAdmin 在 CRUD 时出现 exec() has been disabled for security reasons 处理方法

    然后在看看 禁用函数列表(php.ini)disable_functions = proc_open, popen, exec, system, shell_exec, passthru 这里要把 e ...

  3. ant DatePicker 中文

    方式一:局部设置 import 'moment/locale/zh-cn'; import locale from 'antd/lib/date-picker/locale/zh_CN'; //调用时 ...

  4. PHP 分页 (分页类)

    分页类  以后可直接使用 /** file: page.class.php 完美分页类 Page */ class Page { private $total; //数据表中总记录数 private ...

  5. [svc]linux中的文件描述符(file descriptor)和文件

    linux中的文件描述符(file descriptor)和文件 linux为了实现一切皆文件的设计哲学,不仅将数据抽象成了文件,也将一切操作和资源抽象成了文件,比如说硬件设备,socket,磁盘,进 ...

  6. ASimpleCache源码分析

    ASimpleCache里只有一个JAVA文件——ACache.java,首先我用思维导图制作了ACache类的详细结构图: 通过分析官方给的demo来驱动源码分析吧 以字符串存储为例(官方给的dem ...

  7. Mysql中用SQL增加、删除、修改(包括字段长度/注释/字段名)总结

    转: Mysql中用SQL增加.删除.修改(包括字段长度/注释/字段名)总结 2018年09月05日 10:14:37 桥Dopey 阅读数:1830   版权声明:本文为博主原创文章,未经博主允许不 ...

  8. 阶段3 3.SpringMVC·_05.文件上传_2 文件上传之传统方式上传代码回顾

    先创建表单 enctype选择multipart/form-data 把表单分成几个部分 导入对应的包 解析request拿到上传的文件对象 拿到某个路径的绝对路径 以后什么异常全抛出,改成Excep ...

  9. flask 学习(二)

    安装了flask扩展 以及flask-bootstrap 默认情况下,flask在template文件夹寻找模板. flask 加载的是Jinja2模板,该模板引擎在flask中由函数render_t ...

  10. ubuntu下自动获取ip设置

    vi /etc/network/interfaces文件为如下内容 wq保存 重启网卡:sudo /etc/init.d/networking restart