【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(object):
def heightChecker(self, heights):
"""
:type heights: List[int]
:rtype: int
"""
sorted_heights = sorted(heights)
res = 0
for v1,v2 in zip(heights,sorted_heights):
res += 1 if v1 != v2 else 0
return res
【leetcode】1051. Height Checker的更多相关文章
- 【LeetCode】1051. Height Checker 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序比较 日期 题目地址:https://leetc ...
- 【Leetcode_easy】1051. Height Checker
problem 1051. Height Checker solution class Solution { public: int heightChecker(vector<int>&a ...
- 【LEETCODE】40、1051. Height Checker
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...
- 【LeetCode】BFS(共43题)
[101]Symmetric Tree 判断一棵树是不是对称. 题解:直接递归判断了,感觉和bfs没有什么强联系,当然如果你一定要用queue改写的话,勉强也能算bfs. // 这个题目的重点是 比较 ...
- 【LeetCode】代码模板,刷题必会
目录 二分查找 排序的写法 BFS的写法 DFS的写法 回溯法 树 递归 迭代 前序遍历 中序遍历 后序遍历 构建完全二叉树 并查集 前缀树 图遍历 Dijkstra算法 Floyd-Warshall ...
- 【LeetCode】Island Perimeter 解题报告
[LeetCode]Island Perimeter 解题报告 [LeetCode] https://leetcode.com/problems/island-perimeter/ Total Acc ...
- 【LeetCode】109. Convert Sorted List to Binary Search Tree 解题报告(Python)
[LeetCode]109. Convert Sorted List to Binary Search Tree 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id ...
- 【LeetCode】222. Count Complete Tree Nodes 解题报告(Python)
[LeetCode]222. Count Complete Tree Nodes 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个 ...
- 【LeetCode】554. Brick Wall 解题报告(Python)
[LeetCode]554. Brick Wall 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fux ...
随机推荐
- CMakeLists.txt 语法
命令不区分大小写(参数区分大小写) add_executable(demo main.cpp main.h main.rc) 用main.cpp源文件,main.h文件,main.rc文件构造可执行文 ...
- nginx 入门 安装
.yum解决编译nginx所需的依赖包,之后你的nginx就不会报错了 yum install gcc patch libffi-devel python-devel zlib-devel bzip2 ...
- (转)websphere内存溢出,手动导出was的phd和javacore文件
原文:https://www.cnblogs.com/zhengbn/p/3499700.html 1:服务器-->服务器类型-->WebSphere Application Server ...
- log4j.rootLogger作用域
log4j.rootLogger只对没有申明appender的包起作用:
- 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_09 序列化流_6_练习_序列化集合
- 阶段1 语言基础+高级_1-3-Java语言高级_1-常用API_1_第4节 ArrayList集合_13-ArrayList集合概述和基本使用
新建类 多了个尖括号,大写字母E,这是什么意思呢? 尖括号当中叫做泛型.存储的统一的类型,这个类型就在尖括号里面写上,我们用一个字母占位表示. 如何创建呢 构造方法有三个,最常用的就是无参构造 先掌握 ...
- Java各类型占字节数
byte 1字节short 2字节int 4字节long 8字节float 4字节double 8字节char 2字节boolean 1字节 其中,换算关系: 1GB=1024MB 1MB=1024K ...
- windows7 玩 WinKawaks kof2002为什么提示couldn't initialise DirectSound?
插上 耳机 或者 音响 就ok 呵呵 http://wenwen.sogou.com/z/q200172744.htm windows7 玩 WinKawaks kof2002为什么提示couldn ...
- 20190925 On Java8 第二十二章 枚举
第二十二章 枚举 基本 enum 特性 创建 enum 时,编译器会为你生成一个相关的类,这个类继承自 Java.lang.Enum. valueOf() 是在 Enum 中定义的 static 方法 ...
- 非GUI 模式运行 jmeter 压力测试
非 GUI 模式,即命令行模式,运行 JMeter 测试脚本能够大大缩减所需要的系统资源. 使用命令:jmeter -n -t <testplan filename> -l <lis ...