(一)题目描述
(二)思想方法
先复制数组再排序,最后找不同。
(三)代码实现
class Solution {
public:
int heightChecker(vector<int>& heights) {
vector<int> temp=heights;
sort(heights.begin(), heights.end());
int index = 0;
for (int i = 0; i < heights.size(); ++i)
{
if (temp[i] != heights[i])
{
index++;
}
}
return index;
}
};