【leetcode】高度检查器

 

int heightChecker(int* heights, int heightsSize){
    int hash[101]={0};
    int i,j,count=0;
    
    for (i=0; i<heightsSize; i++)
        hash[heights[i]]++;
    
    for (i=0,j=1; i<heightsSize; j++)
        while(hash[j]-- > 0)
            if (heights[i++] != j)
                count++;            

    return count;
}

 

posted @ 2020-09-26 14:08  温暖了寂寞  阅读(136)  评论(0编辑  收藏  举报