Skip to content

Commit 52d10e2

Browse files
add 1620
1 parent 7aa3ac6 commit 52d10e2

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1620|[Coordinate With Maximum Network Quality](https://leetcode.com/problems/coordinate-with-maximum-network-quality/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1620.java) ||Greedy|Medium|
1112
|1614|[Maximum Nesting Depth of the Parentheses](https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1614.java) ||Easy|String|
1213
|1609|[Even Odd Tree](https://leetcode.com/problems/even-odd-tree/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1609.java) ||Medium|Tree|
1314
|1608|[Special Array With X Elements Greater Than or Equal X](https://leetcode.com/problems/special-array-with-x-elements-greater-than-or-equal-x/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1608.java) ||Easy|Array|
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1620 {
4+
public static class Solution1 {
5+
public static int[] bestCoordinate(int[][] towers, int radius) {
6+
int maxSignal = 0;
7+
int[] best = new int[2];
8+
for (int i = 0; i < towers.length; i++) {
9+
int thisQuality = 0;
10+
for (int j = 0; j < towers.length; j++) {
11+
double distance = Math.sqrt((towers[i][0] - towers[j][0]) * (towers[i][0] - towers[j][0]) + (towers[i][1] - towers[j][1]) * (towers[i][1] - towers[j][1]));
12+
if (distance <= radius) {
13+
thisQuality += Math.floor(towers[j][2] / (1 + distance));
14+
}
15+
}
16+
if (thisQuality > maxSignal) {
17+
maxSignal = thisQuality;
18+
best[0] = towers[i][0];
19+
best[1] = towers[i][1];
20+
} else if (thisQuality == maxSignal) {
21+
if (towers[i][0] < best[0]) {
22+
best[0] = towers[i][0];
23+
best[1] = towers[i][1];
24+
} else if (towers[i][0] == best[0] && towers[i][1] < best[1]) {
25+
best[0] = towers[i][0];
26+
best[1] = towers[i][1];
27+
}
28+
}
29+
}
30+
return best;
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)