https://leetcode.com/problems/height-checker/description/?envType=daily-question&envId=2024-06-11
/**
* @param {number[]} heights
* @return {number}
*/
var heightChecker = function (heights) {
let res = 0
let expected = heights.slice().sort((a, b) => a - b)
for (let i = 0; i < heights.length; i++) {
if (heights[i] !== expected[i]) res++
}
return res
};
Top comments (0)