leetcode-daily/cpp/2206/220613-CN.cpp

15 lines
272 B
C++

#include <vector>
#include <algorithm>
class Solution {
public:
static int heightChecker(const std::vector<int>& h) {
auto x = h;
std::stable_sort(x.begin(), x.end());
int ret = 0;
for (int i = 0; i < x.size(); ++i)
ret += (x[i] != h[i]);
return ret;
}
};