LeetCode solution - 1051. Height Checker - TypeScript and JavaScript

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ต.ค. 2024
  • LeetCode: leetcode.com/p...
    GitHub: github.com/Rus...
    Intuition
    When faced with the problem of determining how many students are not in the correct height order, my initial thought is to compare the original lineup with a correctly sorted lineup. This way, any discrepancies can be easily spotted and counted.
    Approach
    The approach is straightforward: create a sorted copy of the original heights array and then iterate through both arrays simultaneously, counting the positions where the heights differ. This count will give us the number of students out of order.

ความคิดเห็น •