跳转至

人员站位的方案数 I⚓︎

Leetcode题目链接

描述⚓︎

详见中文题目链接

解答⚓︎

class Solution {
public:
    int numberOfPairs(vector<vector<int>>& points) {
        sort(points.begin(), points.end(), [](const auto& p, const auto& q) {
            return p[0] != q[0] ? (p[0] < q[0]) : (p[1] > q[1]);
        });

        int res = 0, n = points.size();
        for (int i = 0; i < n; i++) {
            int y0 = points[i][1];
            int maxY = INT_MIN;
            for (int j = i + 1; j < n; j++) {
                int y = points[j][1];
                if (y <= y0 && y > maxY) {
                    maxY = y;
                    res++;
                }
            }
        }
        return res;
    }
};