标签:数组 com for ble res ret htc check inline
桶排序,时间复杂度\(O(n)\)
class Solution {
public:
int heightChecker(vector<int>& heights) {
int cout[105]={0};
int res=0;
for(auto height:heights){
cout[height]++;
}
int j=0;
for(int i=1;i<105;i++){
while(cout[i]--){
if(heights[j++]!=i) res++;
}
}
return res;
}
};
标签:数组 com for ble res ret htc check inline
原文地址:https://www.cnblogs.com/HurryXin/p/12985362.html