We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
题目链接: https://leetcode-cn.com/problems/height-checker
难度: Easy 标签: 数组 计数排序 排序
Easy
数组
计数排序
排序
The text was updated successfully, but these errors were encountered:
Difficulty: 简单
Related Topics: 数组, 计数排序, 排序
学校打算为全体学生拍一张年度纪念照。根据要求,学生需要按照 非递减 的高度顺序排成一行。
排序后的高度情况用整数数组 expected 表示,其中 expected[i] 是预计排在这一行中第 i 位的学生的高度(下标从 0 开始)。
expected
expected[i]
i
给你一个整数数组 heights ,表示 当前学生站位 的高度情况。heights[i] 是这一行中第 i 位学生的高度(下标从 0 开始)。
heights
heights[i]
返回满足heights[i] != expected[i] 的 下标数量 。
heights[i] != expected[i]
示例:
输入: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] 所有下标的对应学生高度都匹配。
提示:
1 <= heights.length <= 100
1 <= heights[i] <= 100
Language: JavaScript
/** * @param {number[]} heights * @return {number} */ var heightChecker = function(heights) { return [...heights] .sort((a, b) => a - b) .reduce((cnt, height, i) => cnt += height !== heights[i] ? 1 : 0, 0); };
Sorry, something went wrong.
No branches or pull requests
题目链接: https://leetcode-cn.com/problems/height-checker
难度:
Easy
标签:
数组
计数排序
排序
The text was updated successfully, but these errors were encountered: