和为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;
}
执行结果:成功