2022.7.26

class Solution {
public:
    int projectionArea(vector<vector<int>>& grid) {
          int n = grid.size();
        int xyArea = 0, yzArea = 0, zxArea = 0;
        for (int i = 0; i < n; i++) {
            int yzHeight = 0, zxHeight = 0;
            for (int j = 0; j < n; j++) {
                xyArea += grid[i][j] > 0 ? 1 : 0;
                yzHeight = max(yzHeight, grid[j][i]);
                zxHeight = max(zxHeight, grid[i][j]);
            }
            yzArea += yzHeight;
            zxArea += zxHeight;
        }
        return xyArea + yzArea + zxArea;
    }
};

在这里插入图片描述

class Solution {
public:
    int minimumLines(vector<vector<int>>& stockPrices) {
        sort(stockPrices.begin(), stockPrices.end());
        int n = stockPrices.size();
        if (n <= 2) {
            return n - 1;
        }
        int res = 1;
        for (int i = 2; i < n; ++i) {
            long long dx0 = stockPrices[i-1][0] - stockPrices[i-2][0];
            long long dy0 = stockPrices[i-1][1] - stockPrices[i-2][1];
            long long dx1 = stockPrices[i][0] - stockPrices[i-1][0];
            long long dy1 = stockPrices[i][1] - stockPrices[i-1][1];
            if (dx0 * dy1 != dy0 * dx1) {
                ++res;
            }
        }
        return res;
    }
};

在这里插入图片描述

class Solution {
public:
    int GetLenSquare(vector<int> point1, vector<int> point2) {
       return (point2[0] - point1[0]) * (point2[0] - point1[0]) + (point2[1] - point1[1]) * (point2[1] - point1[1]);
    }

    bool validSquare(vector<int>& p1, vector<int>& p2, vector<int>& p3, vector<int>& p4) {
        unordered_set<int> set = 
        {
            GetLenSquare(p1, p2),
            GetLenSquare(p1, p3),
            GetLenSquare(p1, p4),
            GetLenSquare(p2, p3),
            GetLenSquare(p2, p4),
            GetLenSquare(p3, p4)
        };

        if (set.find(0) == set.end() && set.size() == 2)  
        {
            return true;
        }

        return false;
    }
};

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

0x0c……

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值