Skip to content

Commit 4bdae88

Browse files
authored
Create brightest-position-on-street.py
1 parent c134cdb commit 4bdae88

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Time: O(nlogn)
2+
# Space: O(n)
3+
4+
import collections
5+
6+
7+
class Solution(object):
8+
def brightestPosition(self, lights):
9+
"""
10+
:type lights: List[List[int]]
11+
:rtype: int
12+
"""
13+
count = collections.Counter()
14+
for i, r in lights:
15+
count[i-r] += 1
16+
count[i+r+1] -= 1
17+
result = None
18+
max_cnt = cnt = 0
19+
for i, c in sorted(count.iteritems()):
20+
cnt += c
21+
if cnt > max_cnt:
22+
max_cnt, result = cnt, i
23+
return result

0 commit comments

Comments
 (0)