Skip to content

Commit 770dc7d

Browse files
add FlyingDrones1D solution
1 parent 2640a6c commit 770dc7d

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

easiest100/FlyingDrones1D.java

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package easiest100;
2+
3+
public class FlyingDrones1D {
4+
public String findMinTime(String[] positions) {
5+
6+
double dist = 0.0;
7+
8+
for (int i = 0; i < positions.length; i++)
9+
for (int j = i + 1; j < positions.length; j++)
10+
dist = Math.max(Math.abs((Double.parseDouble(positions[i]) / 2 - Double.parseDouble(positions[j]) / 2)),
11+
dist);
12+
13+
// dist = Math.round(dist*100)/100.0 + 0.001;
14+
15+
return String.format("%.2f", dist + 0.001);
16+
}
17+
18+
public static void main(String[] args) {
19+
FlyingDrones1D f = new FlyingDrones1D();
20+
System.out.println(f.findMinTime(new String[] { "1.00", "3.00" }));
21+
System.out.println(f.findMinTime(new String[] { "-135575.03", "2103.82", "-4358.50", "9843.94", "-1319.35",
22+
"8769.30", "-6043.66", "2183.50", "-1015.66", "-200.89", "-3964.38", "74.36", "-9752.16", "-2053.71",
23+
"2238.21", "565.86", "3388.29", "-6950.11", "-8383.31", "5194.07", "-4953.59", "-7999.04", "8747.18",
24+
"4668.17", "-4348.95", "-6528.72", "-7751.13", "-5373.13", "6672.59", "2788.17", "-1121.10", "-6908.90",
25+
"1085.73", "9814.95", "-1417.15", "2281.51", "3944.57", "-7786.14", "-3692.73", "3211.29", "2853.94",
26+
"-1949.05", "-462.70", "525.36", "275487.16" }));
27+
}
28+
29+
}

0 commit comments

Comments
 (0)