Skip to content

Commit bd004e2

Browse files
authored
Create count-covered-buildings.py
1 parent 4e0700e commit bd004e2

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Python/count-covered-buildings.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Time: O(n)
2+
# Space: O(n)
3+
4+
# array
5+
class Solution(object):
6+
def countCoveredBuildings(self, n, buildings):
7+
"""
8+
:type n: int
9+
:type buildings: List[List[int]]
10+
:rtype: int
11+
"""
12+
left = [n]*n
13+
right = [-1]*n
14+
up = [-1]*n
15+
down = [n]*n
16+
for x, y in buildings:
17+
x -= 1
18+
y -= 1
19+
left[y] = min(left[y], x)
20+
right[y] = max(right[y], x)
21+
up[x] = max(up[x], y)
22+
down[x] = min(down[x], y)
23+
return sum(left[y-1] < x-1 < right[y-1] and down[x-1] < y-1 < up[x-1] for x, y in buildings)

0 commit comments

Comments
 (0)