当前位置:网站首页>LeetCode1051(C#)
LeetCode1051(C#)
2022-07-07 15:38:00 【有趣就行】
题目
学校打算为全体学生拍一张年度纪念照。根据要求,学生需要按照 非递减 的高度顺序排成一行。
排序后的高度情况用整数数组 expected 表示,其中 expected[i] 是预计排在这一行中第 i 位的学生的高度(下标从 0 开始)。
给你一个整数数组 heights ,表示 当前学生站位 的高度情况。heights[i] 是这一行中第 i 位学生的高度(下标从 0 开始)。
返回满足 heights[i] != expected[i] 的 下标数量 。
示例1:
输入:heights = [1,1,4,2,1,3]
输出:3
解释:
高度:[1,1,4,2,1,3]
预期:[1,1,1,2,3,4]
下标 2 、4 、5 处的学生高度不匹配。
示例 2:
输入:heights = [5,1,2,3,4]
输出:5
解释:
高度:[5,1,2,3,4]
预期:[1,2,3,4,5]
所有下标的对应学生高度都不匹配。
示例 3:
输入:heights = [1,2,3,4,5]
输出:0
解释:
高度:[1,2,3,4,5]
预期:[1,2,3,4,5]
所有下标的对应学生高度都匹配。
代码
- Linq 一句扫天下
public class Solution
{
public int HeightChecker(int[] heights)
{
return heights.OrderBy(h => h).
Zip(heights, (e,h) => (first : e, second : h)).
Count(eh => eh.first != eh.second);
}
}
边栏推荐
- 测试用例管理工具推荐
- LeetCode 120. Triangle minimum path and daily question
- Establishment of solid development environment
- 麒麟信安操作系统衍生产品解决方案 | 存储多路径管理系统,有效提高数据传输可靠性
- User defined view essential knowledge, Android R & D post must ask 30+ advanced interview questions
- QT 图片背景色像素处理法
- Skimage learning (3) -- adapt the gray filter to RGB images, separate colors by immunohistochemical staining, and filter the maximum value of the region
- Sator推出Web3游戏“Satorspace” ,并上线Huobi
- DNS 系列(一):为什么更新了 DNS 记录不生效?
- L1-027 出租(Lua)
猜你喜欢

MRS离线数据分析:通过Flink作业处理OBS数据

PLC:自动纠正数据集噪声,来洗洗数据集吧 | ICLR 2021 Spotlight

Matplotlib绘制三维图形

测试用例管理工具推荐
Share the latest high-frequency Android interview questions, and take you to explore the Android event distribution mechanism

【图像传感器】相关双采样CDS

Sator推出Web3游戏“Satorspace” ,并上线Huobi

AI来搞财富分配比人更公平?来自DeepMind的多人博弈游戏研究

管理VDI的几个最佳实践

QML初学
随机推荐
Siggraph 2022 best technical paper award comes out! Chen Baoquan team of Peking University was nominated for honorary nomination
Biped robot controlled by Arduino
LeetCode 1031. 两个非重叠子数组的最大和 每日一题
浅浅理解.net core的路由
Jenkins发布uniapp开发的H5遇到的问题
LeetCode 1477. 找两个和为目标值且不重叠的子数组 每日一题
LeetCode 403. 青蛙过河 每日一题
LeetCode 213. 打家劫舍 II 每日一题
First in China! Todesk integrates RTC technology into remote desktop, with clearer image quality and smoother operation
Flask build API service SQL configuration file
SIGGRAPH 2022最佳技术论文奖重磅出炉!北大陈宝权团队获荣誉提名
管理VDI的几个最佳实践
Skimage learning (2) -- RGB to grayscale, RGB to HSV, histogram matching
麒麟信安中标国网新一代调度项目!
LeetCode 1774. The dessert cost closest to the target price is one question per day
【图像传感器】相关双采样CDS
L1-027 出租(Lua)
[Seaborn] combination chart: pairplot and jointplot
PLC: automatically correct the data set noise, wash the data set | ICLR 2021 spotlight
浅谈 Apache Doris FE 处理查询 SQL 源码解析