1,题目描述
2,题目分析
1,排序
2,对比
3,代码实现
class Solution {
public:
int heightChecker(vector<int>& heights) {
int n=heights.size();
vector<int> tmp=heights;
sort(tmp.begin(),tmp.end());
int res=0;
for(int i=0;i<n;i++)
{
if(tmp[i]!=heights[i])
{
res++;
}
}
return res;
}
};