Skip to content

Commit 048ec1b

Browse files
authored
Create coordinate-with-maximum-network-quality.py
1 parent 7febb87 commit 048ec1b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Time: O(n^2)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def bestCoordinate(self, towers, radius):
6+
"""
7+
:type towers: List[List[int]]
8+
:type radius: int
9+
:rtype: List[int]
10+
"""
11+
min_x = min(towers, key=lambda x:x[0])[0]
12+
max_x = max(towers, key=lambda x:x[0])[0]
13+
min_y = min(towers, key=lambda x:x[1])[1]
14+
max_y = max(towers, key=lambda x:x[1])[1]
15+
max_quality = 0
16+
for x in xrange(min_x, max_x+1):
17+
for y in xrange(min_y, max_y+1):
18+
q = 0
19+
for nx, ny, nq in towers:
20+
d = ((nx-x)**2+(ny-y)**2)**0.5
21+
if d <= radius:
22+
q += int(nq/(1+d))
23+
if q > max_quality:
24+
max_quality = q
25+
result = x, y
26+
return result

0 commit comments

Comments
 (0)