0
点赞
收藏
分享

微信扫一扫

【Leetcode-每日一题】可以形成最大正方形的矩形数目

目标践行者 2022-02-04 阅读 46

和为K的最少斐波那契数字数目
难度:简单
在这里插入图片描述
通过遍历得到每个矩形的最短边,并记录最大正方形的边长max,同时记录max出现的次数res。遍历后得到结果。
代码如下:

	public int countGoodRectangles(int[][] rectangles) {
        int res = 0;
        int max = 0;
        for (int[] rec : rectangles){
            int temp = rec[0]<rec[1] ? rec[0]:rec[1];
            if (temp>max){
                max = temp;
                res = 1;
            }else if(temp==max){
                res++;
            }
        }
        return res;
    }

执行结果:成功
在这里插入图片描述

举报

相关推荐

0 条评论