跳转至

求交集区域内的最大正方形面积⚓︎

Leetcode题目链接

描述⚓︎

详见中文题目链接

解答⚓︎

class Solution {
public:
    long long largestSquareArea(vector<vector<int>>& bottomLeft, vector<vector<int>>& topRight) {
        long long res = 0;
        for (int i = 0; i < bottomLeft.size(); i++) {
            auto& b1 = bottomLeft[i];
            auto& t1 = topRight[i];
            for (int j = i + 1; j < bottomLeft.size(); j++) {
                auto& b2 = bottomLeft[j];
                auto& t2 = topRight[j];
                int height = min(t1[1], t2[1]) - max(b1[1], b2[1]);
                int width = min(t1[0], t2[0]) - max(b1[0], b2[0]);
                int size = min(width, height);
                if (size > 0) {
                    res = max(res, static_cast<long long>(size) * size);
                }
            }
        }
        return res;
    }
};