zangdaiyang 2020-05-29
桶排序,时间复杂度\(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; } };