MJay
750 본문
Given a grid where each entry is only 0 or 1, find the number of corner rectangles.
A corner rectangle is 4 distinct 1s on the grid that form an axis-aligned rectangle. Note that only the corners need to have the value 1. Also, all four 1s used must be distinct.
Example 1:
Input: grid = [[1, 0, 0, 1, 0], [0, 0, 1, 0, 1], [0, 0, 0, 1, 0], [1, 0, 1, 0, 1]] Output: 1 Explanation: There is only one corner rectangle, with corners grid[1][2], grid[1][4], grid[3][2], grid[3][4].
Example 2:
Input: grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]] Output: 9 Explanation: There are four 2x2 rectangles, four 2x3 and 3x2 rectangles, and one 3x3 rectangle.
Example 3:
Input: grid = [[1, 1, 1, 1]] Output: 0 Explanation: Rectangles must have four distinct corners.
먼저 Counter() 이건 Key, Value로 세주는것이다
enumerate를 통해 index 와 값을 가지고있는다.
그리고 <----> 이런 length의 counter를 가지고있으면 된다.
그걸 count[c1,c2] 로 가지고있으면 됩니다.
return ans
DP는 아니네
'Programming > LeetCode' 카테고리의 다른 글
1161 (0) | 2019.10.28 |
---|---|
997 (0) | 2019.10.27 |
338 Bits (0) | 2019.10.22 |
276 - DP - (문제 잘 읽어야하는 이유) (0) | 2019.10.22 |
198 - DP - House Robber (0) | 2019.10.21 |