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. Button.OnClientClick

    Button.OnClientClick Gets or sets the client-side script that executes when a Button control's Click ...

  2. vue 登录路由判断

    router.beforeEach((to, from, next) => { // alert(sessionStorage.getItem('accessToken')) // consol ...

  3. CallableStatement获得存储过程多个结果集

    这里使用到的数据库为MySQL package com.dz.entity; import java.sql.*; public class Pro_inoutTest { public static ...

  4. 七十四:flask信号之flask的内置信号

    flask所有的内置信号 1.template_rendered:模板渲染完成后的信号2.before_render_template:模板渲染之前的信号3.request_started:模板开始渲 ...

  5. 创建podspec文件,为自己的项目添加pod支持

    Cocoapods作为iOS开发的包管理器,给我们的开发带来了极大的便利,而且越来越多的第三方类库支持Pod,可以通过Pod傻瓜式的集成到自己的工程中,那么问题来了,我自己也有一系列的小工具类,怎么让 ...

  6. 【JVM学习笔记】类加载过程

    在Java代码中,类型的加载.连接与初始化过程都是在程序运行期间完成的:提供了更大的灵活性,增加了更多的可能性 JVM启动过程包括:加载.连接.初始化 加载:就是将class文件加载到内存.详细的说是 ...

  7. js高程之作用域

    我们知道js执行环境有全局环境(window)和局部环境(一般指函数环境)之分. ; function calc(){ ; } 上述代码,虽然有两个num变量,但是他们所在的执行环境却是不同的,第一个 ...

  8. MyEclipse 下'Publishing to Tomcat'has encountered a problem解决办法

    详情查看: MyEclipse 下'Publishing to Tomcat'has encountered a problem解决办法

  9. vscode 中sftp配置

    简单记录一下,相对路径的设置不用“/”表明根目录等,直接写目录名字即可 {     "name": "profile name",     "prot ...

  10. Java生成二维码连接

    本文使用的是Goodge的zxing 添加maven依赖 <dependency> <groupId>com.google.zxing</groupId> < ...