Thursday, March 4, 2021

Leetcode Everyday: 1725. Number Of Rectangles That Can Form The Largest Square. Easy

public class Solution {
    public int CountGoodRectangles(int[][] rectangles) {
        var minCounts = new Dictionary<int, int>();    
        
        foreach (var r in rectangles) {
            var min = Math.Min(r[0], r[1]);           
            minCounts[min] = 
                (minCounts.TryGetValue(min, out int value) ? value : 0) + 1;        
        }
                            
        return minCounts[minCounts.Keys.Max()];
    }    
}
Source: https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square/

No comments:

Post a Comment