leetcode--max-points-on-a-line
来源:互联网 发布:无法无天小说吾知 编辑:程序博客网 时间:2024/06/06 11:46
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.
分析:2点确定一条直线,在这个过程中,需要注意和第一个重复的点,这个点只能看成一个
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.
public class Solution { public int maxPoints(Point[] points) { int len=points.length; if(len<=2)return len; int maxNum=2; int x1=0,x2=0,y1=0,y2=0; for(int i=0;i<len;i++){ int num=0;//记录每个和第一个点重复的点 for(int j=i+1;j<len;j++){ int temp=1; x1=points[j].x-points[i].x; y1=points[j].y-points[i].y; if(x1==0&&y1==0){ num++; }else{ temp++; for(int k=j+1;k<len;k++){ x2=points[k].x-points[j].x; y2=points[k].y-points[j].y; if(x1*y2==y1*x2){ temp++; } } } if(maxNum<temp+num){ maxNum=temp+num; } } } return maxNum; }}
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.
阅读全文
0 0
- 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)
- leetcode:【Max Points on a Line】
- 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(149)Max Points on a Line
- 教你如何学习自动化测试
- 计算机网络基础知多少
- Project facet Java 1.8 is not supported by target runtime Apache Tomcat v8.0解决
- Android adb shell KeyCode列表
- 算法练习_LeetCode_链表1
- leetcode--max-points-on-a-line
- set集合和list集合的区别
- 正则表达式 REGEXP_REPLACE
- 推荐文章之从技术、平台、工具、语言&框架等四大方面,详解技术未来的趋势
- 网络端口
- 【bzoj1532】[POI2005]Kos-Dicing
- Android _TopBarView
- Matlab图形绘制经典案例 (1)
- VS2015/2017无法启动UWP设计器,显示"从位置 Microsoft.NET.CoreRuntime.1.1.appx 中打开程序包失败"的问题解决