DEV Community

Karleb
Karleb

Posted on

#1051. Height Checker

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
};

Enter fullscreen mode Exit fullscreen mode

Top comments (0)