题目如下:

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(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的更多相关文章

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

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

  2. 【Leetcode_easy】1051. Height Checker

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

  3. 【LEETCODE】40、1051. Height Checker

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

  4. 【LeetCode】BFS(共43题)

    [101]Symmetric Tree 判断一棵树是不是对称. 题解:直接递归判断了,感觉和bfs没有什么强联系,当然如果你一定要用queue改写的话,勉强也能算bfs. // 这个题目的重点是 比较 ...

  5. 【LeetCode】代码模板,刷题必会

    目录 二分查找 排序的写法 BFS的写法 DFS的写法 回溯法 树 递归 迭代 前序遍历 中序遍历 后序遍历 构建完全二叉树 并查集 前缀树 图遍历 Dijkstra算法 Floyd-Warshall ...

  6. 【LeetCode】Island Perimeter 解题报告

    [LeetCode]Island Perimeter 解题报告 [LeetCode] https://leetcode.com/problems/island-perimeter/ Total Acc ...

  7. 【LeetCode】109. Convert Sorted List to Binary Search Tree 解题报告(Python)

    [LeetCode]109. Convert Sorted List to Binary Search Tree 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id ...

  8. 【LeetCode】222. Count Complete Tree Nodes 解题报告(Python)

    [LeetCode]222. Count Complete Tree Nodes 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个 ...

  9. 【LeetCode】554. Brick Wall 解题报告(Python)

    [LeetCode]554. Brick Wall 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fux ...

随机推荐

  1. qbzt day3 上午

    内容提要 堆 lca(最近公共祖先) st表 hash 并查集 树状数组 线段树 数据结构 1.堆 Priority_queue 他滋兹:插入删除查询最大值(最小值) 分为大根堆小根堆 2.LCA 首 ...

  2. thinkphp5.0学习笔记(一)基础知识与URL访问

    1.目录结构: 其中thinkphp子目录是框架核心目录 thinkphp结构: 2.入口文件 默认自带的入口文件位于public/index.php 应用目录为application,其结构: in ...

  3. 券商VIP交易通道

    打新不成就炒新.随着新股发行上市的再次重启,巨大的获利机会引来投资者的争相竞逐,可并非所有投资者都能抢到新股筹码.“每天都在涨停板追这些新股,但从来没有买到过.”证券时报记者在采访中听到不少中小散户如 ...

  4. EditPlus配色方案

    找到配置文件:editplus_u.ini配置文件 [Options] Placement=2C00000002000000030000000083FFFF0083FFFFFFFFFFFFFFFFFF ...

  5. 【SD系列】SAP 创建销售订单-用外部给号的方法步骤

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[SD系列]SAP 创建销售订单-用外部给号的方 ...

  6. 【MM系列】SAP 主要模块及简介

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP 主要模块及简介   前言部分 ...

  7. ETROBOT——审题

    参加了比赛,但是总要理解比赛相关的东西,发现以前瞎写的东西有人看,并且还有挺多人看的,所以打算继续在这里面,做记录. 源: http://www.etrobo.jp/2018/gaiyou/intro ...

  8. jdbc步骤:

    一.注册数据库驱动 Class.forName("com.mysql.jdbc.Driver"); 二.建立连接(Connection) Connection conn = Dri ...

  9. A heavy dew refreshed the earth at night

    brightness.n.明亮 endless.adj.无止境的 degradation.n.堕落 superiority.n.优越性 valuable.adj.有价值的 flake.n.小薄片 cu ...

  10. 002/区块链核心概念与原理详解(Mooc)

    1.课程介绍 (一).区块链前世今生 密码朋克--神秘组织(邮件组) 2.区块链核心概念与原理 (一)比特币是数字货币 为什么叫区块链? 因为比特币系统里面的数据是一个个的区块来存储,并且通过hash ...