1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// @Title: 可以形成最大正方形的矩形数目 (Number Of Rectangles That Can Form The Largest Square)
// @Author: 15816537946@163.com
// @Date: 2022-02-04 10:14:51
// @Runtime: 20 ms
// @Memory: 6.4 MB
func countGoodRectangles(rectangles [][]int) int {
    var maxSize,cnt int
    for _, v := range rectangles {
        currentMax := min(v[0],v[1])

        if currentMax == maxSize {
            cnt++
        } else if  currentMax > maxSize{
            maxSize,cnt  = currentMax, 1
        }
    }

    return cnt
}

func min(a,b int) int {
    if a > b {
        return b
    }
    return a
}