【Leetcode_easy】1051. Height Checker

problem

1051. Height Checker

solution

class Solution {
public:
    int heightChecker(vector<int>& heights) {
        vector<int> orders = heights;
        sort(orders.begin(), orders.end());
        int res = 0;
        for(int i=0; i<heights.size(); i++)
        {
            if(heights[i]!=orders[i]) res++;
        }
        return res;
    }
};

参考

1. Leetcode_easy_1051. Height Checker;

原文地址:https://www.cnblogs.com/happyamyhope/p/11431236.html