当前位置:网站首页>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);
}
}
边栏推荐
- skimage学习(3)——使灰度滤镜适应 RGB 图像、免疫组化染色分离颜色、过滤区域最大值
- First in China! Todesk integrates RTC technology into remote desktop, with clearer image quality and smoother operation
- [Seaborn] combination chart: facetgrid, jointgrid, pairgrid
- Notes on installing MySQL in centos7
- 麒麟信安携异构融合云金融信创解决方案亮相第十五届湖南地区金融科技交流会
- 【饭谈】那些看似为公司着想,实际却很自私的故事 (一:造轮子)
- [Seaborn] combination chart: pairplot and jointplot
- Number of exchanges in the 9th Blue Bridge Cup finals
- 【图像传感器】相关双采样CDS
- Repair method of firewall system crash and file loss, material cost 0 yuan
猜你喜欢
Sator推出Web3遊戲“Satorspace” ,並上線Huobi
Nerf: the ultimate replacement for deepfake?
Sator launched Web3 game "satorspace" and launched hoobi
Pycharm IDE下载
专精特新软件开发类企业实力指数发布,麒麟信安荣誉登榜
SIGGRAPH 2022最佳技术论文奖重磅出炉!北大陈宝权团队获荣誉提名
skimage学习(2)——RGB转灰度、RGB 转 HSV、直方图匹配
Pychart ide Download
mysql官网下载:Linux的mysql8.x版本(图文详解)
LeetCode刷题day49
随机推荐
Blue Bridge Cup final XOR conversion 100 points
The server is completely broken and cannot be repaired. How to use backup to restore it into a virtual machine without damage?
Shallow understanding Net core routing
Mrs offline data analysis: process OBS data through Flink job
How to mount the original data disk without damage after the reinstallation of proxmox ve?
With the latest Alibaba P7 technology system, mom doesn't have to worry about me looking for a job anymore
The top of slashdata developer tool is up to you!!!
LeetCode 648(C#)
First in China! Todesk integrates RTC technology into remote desktop, with clearer image quality and smoother operation
LeetCode 1477. Find two subarrays with sum as the target value and no overlap
MySQL implements the query of merging two fields into one field
LeetCode 300. Daily question of the longest increasing subsequence
LeetCode 1654. The minimum number of jumps to get home one question per day
LeetCode 1986. The minimum working time to complete the task is one question per day
skimage学习(1)
Flash build API service
Pycharm IDE下载
LeetCode 1186. Delete once to get the sub array maximum and daily question
LeetCode 1774. 最接近目标价格的甜点成本 每日一题
Flask搭建api服务