1137. Height Checker
My accepted C++ solution to LeetCode problem 1137, Height Checker, running in 0ms.
- Difficulty: Easy
- C++
- Runtime 0ms
- Memory 11.5MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
C++
Accepted on LeetCode — runtime 0ms, memory 11.5MB, accepted 2025-12-27.
class Solution {
public:
int heightChecker(vector<int>& heights) {
vector<int> expected = heights;
sort(expected.begin(), expected.end());
int count = 0;
for (int i = 0; i < heights.size(); i++) {
if (heights[i] != expected[i]) count++;
}
return count;
}
};