Skip to content

Commit

Permalink
Update Solution.java
Browse files Browse the repository at this point in the history
  • Loading branch information
yanglbme authored Aug 13, 2024
1 parent 6114d4e commit 3bfcd2d
Showing 1 changed file with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import java.util.*;

public class Solution {
class Solution {
public int numPoints(int[][] darts, int r) {
int n = darts.length;
int maxDarts = 1;

for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
List<double[]> centers = possibleCenters(darts[i][0], darts[i][1], darts[j][0], darts[j][1], r);
List<double[]> centers
= possibleCenters(darts[i][0], darts[i][1], darts[j][0], darts[j][1], r);
for (double[] center : centers) {
maxDarts = Math.max(maxDarts, countDarts(center[0], center[1], darts, r));
}
Expand All @@ -30,8 +29,8 @@ private List<double[]> possibleCenters(int x1, int y1, int x2, int y2, int r) {
double offsetX = distToCenter * dy / d;
double offsetY = distToCenter * -dx / d;

centers.add(new double[]{midX + offsetX, midY + offsetY});
centers.add(new double[]{midX - offsetX, midY - offsetY});
centers.add(new double[] {midX + offsetX, midY + offsetY});
centers.add(new double[] {midX - offsetX, midY - offsetY});
return centers;
}

Expand All @@ -44,10 +43,4 @@ private int countDarts(double x, double y, int[][] darts, int r) {
}
return count;
}

public static void main(String[] args) {
Solution solution = new Solution();
System.out.println(solution.numPoints(new int[][]{{-2,0},{2,0},{0,2},{0,-2}}, 2)); // Output: 4
System.out.println(solution.numPoints(new int[][]{{-3,0},{3,0},{2,6},{5,4},{0,9},{7,8}}, 5)); // Output: 5
}
}

0 comments on commit 3bfcd2d

Please sign in to comment.