Leet Code Daily 2024-06-10 - Height Checker
Solution
class Solution {
public:
int heightChecker(vector<int>& heights) {
vector<int> expected(heights.begin(), heights.end());
sort(expected.begin(), expected.end());
int ans = 0;
for (int i = 0; i < heights.size(); i++) {
if (heights[i] != expected[i]) {
ans++;
}
}
return ans;
}
};