网站开发职业认知小结,一个人做网站要多久,计算机软件培训机构哪个好,用dw做的个人网站学校打算为全体学生拍一张年度纪念照。根据要求#xff0c;学生需要按照 非递减 的高度顺序排成一行。
排序后的高度情况用整数数组 expected 表示#xff0c;其中 expected[i] 是预计排在这一行中第 i 位的学生的高度#xff08;下标从 0 开始#xff09;。
给你一个整数…学校打算为全体学生拍一张年度纪念照。根据要求学生需要按照 非递减 的高度顺序排成一行。
排序后的高度情况用整数数组 expected 表示其中 expected[i] 是预计排在这一行中第 i 位的学生的高度下标从 0 开始。
给你一个整数数组 heights 表示 当前学生站位 的高度情况。heights[i] 是这一行中第 i 位学生的高度下标从 0 开始。
返回满足 heights[i] ! expected[i] 的 下标数量 。 思路排序后进行比较计数即可。懒得手撕排序了直接上sort函数 #include iostream
#include vector
#include algorithmusing namespace std;class Solution {
public:int heightChecker(vectorint heights) {vectorint sorted heights;sort(sorted.begin(), sorted.end());int count 0;for (int i 0; i heights.size(); i){if (heights[i] ! sorted[i])count;}return count;}
};int main(){Solution s;vectorint heights {1,1,4,2,1,3};cout s.heightChecker(heights) endl;return 0;
}