heights
를 정렬된 상태로 만든 복제 배열을 정의nonExpects
: 일치하지 않는 요소의 수1
을 순회하며 각 요소의 불일치 비교function heightChecker(heights: number[]): number {
const sorted = heights.toSorted((a, b) => a - b)
let nonExpects = 0
for(let i = 0; i < heights.length; i++) {
if(heights[i] !== sorted[i]) nonExpects++
}
return nonExpects
};