Skip to content

Commit 96876eb

Browse files
committed
add code
1 parent 0bbe82d commit 96876eb

File tree

4 files changed

+389
-10
lines changed

4 files changed

+389
-10
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* @lc app=leetcode.cn id=1620 lang=java
3+
*
4+
* [1620] 网络信号最好的坐标
5+
*/
6+
7+
// @lc code=start
8+
class Solution {
9+
public int[] bestCoordinate(int[][] towers, int radius) {
10+
11+
int xMax = Integer.MIN_VALUE;
12+
int yMax = Integer.MIN_VALUE;
13+
14+
for (int[] tower: towers) {
15+
xMax = xMax > tower[0] ? xMax : tower[0];
16+
yMax = yMax > tower[1] ? yMax : tower[1];
17+
}
18+
19+
20+
int sum = 0;
21+
int[] r = {0, 0};
22+
23+
for (int x = 0; x < xMax + 1; x++) {
24+
for (int y = 0; y < yMax + 1; y++) {
25+
int s = 0;
26+
for (int j = 0; j < towers.length; j++) {
27+
int xx = x - towers[j][0];
28+
int yy = y - towers[j][1];
29+
double z = Math.sqrt(xx * xx + yy * yy);
30+
if (z <= radius) {
31+
s += Math.floor(towers[j][2] / (1 + z));
32+
}
33+
}
34+
if (s > sum) {
35+
sum = s;
36+
r[0] = x;
37+
r[1] = y;
38+
}
39+
}
40+
}
41+
42+
return r;
43+
}
44+
}
45+
// @lc code=end
46+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import java.util.ArrayList;
2+
import java.util.HashMap;
3+
import java.util.List;
4+
import java.util.Map;
5+
6+
import javax.lang.model.element.Element;
7+
8+
/*
9+
* @lc app=leetcode.cn id=599 lang=java
10+
*
11+
* [599] 两个列表的最小索引总和
12+
*/
13+
14+
// @lc code=start
15+
class Solution {
16+
public String[] findRestaurant(String[] list1, String[] list2) {
17+
18+
Map<String, Integer> ss = new HashMap<>();
19+
for (int i = 0; i < list2.length; i++) {
20+
ss.put(list2[i], i);
21+
}
22+
23+
List<String> rs = new ArrayList<>();
24+
int m = Integer.MAX_VALUE;
25+
for (int i = 0; i < list1.length; i++) {
26+
if (ss.containsKey(list1[i])) {
27+
int j = ss.get(list1[i]) + i;
28+
if (j < m) {
29+
rs.clear();
30+
m = j;
31+
32+
} else if (j > m) {
33+
continue;
34+
}
35+
rs.add(list1[i]);
36+
}
37+
}
38+
39+
return rs.toArray(new String[0]);
40+
}
41+
}
42+
// @lc code=end
43+

0 commit comments

Comments
 (0)