LeetCode 149 Max Points on a Line
来源:互联网 发布:网络战略游戏图片 编辑:程序博客网 时间:2024/05/19 04:52
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.
在一个平面上有n个点,求一条直线最多能够经过多少个这些点。
Runtime: 10 ms beats 99.93% of java submissions
public int maxPoints(Point[] points) {int n = points.length;if (n < 2) return n;int currentL, maxL = 2, x, y, dx, dy, overlap = 0, upperB = n;for (int i = 0; i < upperB; i++) {for (int j = i + 1; j < n; j++) {currentL = 1;x = points[i].y - points[j].y;y = points[j].x - points[i].x;if (x == 0 && y == 0) overlap++;else {currentL++;for (int k = j + 1; k < n && currentL + n - k > maxL; k++) {dx = points[k].x - points[i].x;dy = points[k].y - points[i].y;if (x * dx + y * dy == 0)currentL++;}}maxL = Math.max(currentL + overlap, maxL);}upperB = n - maxL;overlap = 0;}return maxL;}https://discuss.leetcode.com/topic/3991/my-java-accepted-solution-for-your-reference-only-using-array
0 0
- LeetCode(149)Max Points on a Line
- LeetCode: Max Points on a Line [149]
- LeetCode # 149 Max Points on a Line
- leetcode 149: Max Points on a Line
- Leetcode 149 Max Points on a Line
- LeetCode 149 Max Points on a Line
- Max Points on a Line | leetcode
- Max Points on a Line LEETCODE
- Leetcode: Max Points on a Line
- LeetCode - Max Points on a Line
- LeetCode 之 Max Points on a Line
- LeetCode | Max Points on a Line
- [LeetCode] Max Points on a Line
- Leetcode: Max Points on a Line
- LeetCode OJ:Max Points on a Line
- Leetcode Max Points on a Line
- Leetcode: Max Points on a Line .
- [Leetcode] Max Points on a Line (Java)
- java响应式
- 那些年踩过华为手机的坑——相同的代码不同的效果
- Spring学习02--属性编辑器
- 如何在 Ubuntu 中检查 CPU ,显卡,内存,硬盘的使用情况及温度等信息
- 进程的执行退出函数
- LeetCode 149 Max Points on a Line
- Unity中的贝塞尔曲线思路及实现
- Lwip ARP分析(2)
- 测试
- 深度学习框架Caffe源码解析
- POJ2217——Secretary
- 第十六周项目2-大数据集上排序算法性能的体验
- 二叉树相关的面试题<一>
- P1540 机器翻译 NOIP2010提高D1