描述 班上的学生根据他们的年级照片的身高升序排列,确定当前未站在正确位置的学生人数
数组长度 <= 10^5
示例
输入: heights = [1,1,3,3,4,1]
输出: 3
解释: 经过排序后 heights变成了[1,1,1,3,3,4],有三个学生不在应在的位置上
class Solution {
public:
/**
* @param heights: Students height
* @return: How many people are not where they should be
*/
int orderCheck(vector<int> &heights) {
// write your code here
vector<int> arr = heights;
sort(heights.begin(), heights.end());
int count = 0;
for(int i = 0; i < arr.size(); i++)
{
if(arr[i] != heights[i])
count++;
}
return count;
}
};
101ms C++