@Test public void noPointIsNoLine() throws Exception { Solution solution = new Solution(); int maxPoints = solution.maxPoints(new Point[]{}); assertThat(maxPoints, is(0)); }
public int maxPoints(Point[] points) { if (points.length == 0) { return 0; } else { int max = 1; for (int i = 0; i < points.length; i++) { int samePoints = 0; Point a = points[i]; HashMap<Double, Integer> linesStartWithA = new HashMap<>(); for (int j = i + 1; j < points.length; j++) { Point b = points[j]; int deltaX = a.x - b.x; int deltaY = a.y - b.y; if (deltaX == 0 && deltaY == 0) { samePoints++; continue; } Double angle = calcAngle(deltaX, deltaY); updateLines(linesStartWithA, angle); } max = updateMax(max, linesStartWithA, samePoints); } return max; } }
Solution { public int maxPoints(Point[] points) { if (points.length == 0) { return 0; } else { int max = 1; for (int i = 0; i < points.length; i++) { int samePoints = 0; Point a = points[i]; HashMap<Double, Integer> linesStartWithA = new HashMap<>(); for (int j = i + 1; j < points.length; j++) { Point b = points[j]; int deltaX = a.x - b.x; int deltaY = a.y - b.y; if (deltaX == 0 && deltaY == 0) { samePoints++; continue; } Double angle = calcAngle(deltaX, deltaY); updateLines(linesStartWithA, angle); } max = updateMax(max, linesStartWithA, samePoints); } return max; } } }
Solution { public int maxPoints(Point[] points) { if (points.length == 0) { return 0; } else { int max = 1; for (int i = 0; i < points.length; i++) { int samePoints = 0; Point a = points[i]; HashMap<Double, Integer> linesStartWithA = new HashMap<>(); for (int j = i + 1; j < points.length; j++) { Point b = points[j]; int deltaX = a.x - b.x; int deltaY = a.y - b.y; if (deltaX == 0 && deltaY == 0) { samePoints++; continue; } Double angle = calcAngle(deltaX, deltaY); updateLines(linesStartWithA, angle); } max = updateMax(max, linesStartWithA, samePoints); } return max; } }  }
Solution { public int maxPoints(Point[] points) { if (points.length == 0) { return 0; } else { int max = 1; for (int i = 0; i < points.length; i++) { int samePoints = 0; Point a = points[i]; HashMap<Double, Integer> linesStartWithA = new HashMap<>(); for (int j = i + 1; j < points.length; j++) { Point b = points[j]; int deltaX = a.x - b.x; int deltaY = a.y - b.y; if (deltaX == 0 && deltaY == 0) { samePoints++; continue; } Double angle = calcAngle(deltaX, deltaY); updateLines(linesStartWithA, angle); } max = updateMax(max, linesStartWithA, samePoints); } return max; } }  int maxPoints(Point[] points); }
Solution { public int maxPoints(Point[] points) { if (points.length == 0) { return 0; } else { int max = 1; for (int i = 0; i < points.length; i++) { int samePoints = 0; Point a = points[i]; HashMap<Double, Integer> linesStartWithA = new HashMap<>(); for (int j = i + 1; j < points.length; j++) { Point b = points[j]; int deltaX = a.x - b.x; int deltaY = a.y - b.y; if (deltaX == 0 && deltaY == 0) { samePoints++; continue; } Double angle = calcAngle(deltaX, deltaY); updateLines(linesStartWithA, angle); } max = updateMax(max, linesStartWithA, samePoints); } return max; } }  int maxPoints(Point[] points);  }