leetcode_Max Points on a Line
2014-05-13 10:27
295 查看
/* * Max Points on a Line * */ public int maxPoints(Point[] points) { int max = 0; for(int i=0;i<points.length-1;i++) { for(int j=i+1;j<points.length;j++) { int num=0; //if this 2 points are the same , skip this time, or we'll get result 'n' which is probably not correct! if(points[j].x == points[i].x && points[j].y == points[i].y) { continue; } for(int k=0;k<points.length;k++) { int isLine = (points[i].y-points[k].y)*(points[j].x-points[k].x)-(points[j].y-points[k].y)*(points[i].x-points[k].x); if(isLine==0) { num++; } } if(num>max) { max = num; } } } //if only one or two points, above judgement will get result 0 while the correct result is 1 or 2 if(points.length<=2) { max = points.length; } else if(max==0) { // this case is that all points are the same max=points.length; } return max; }
相关文章推荐
- 【leetcode】Max Points on a Line (python)
- Leetcode: Max Points on a Line
- Leetcode-Max Points on a Line
- LeetCode 149. Max Points on a Line
- LeetCode---3.Max Points on a Line
- leetcode 刷题之路 3 Max Points on a Line
- [leetcode]Max Points on a Line @ Python
- [Leetcode]Max Points on a Line
- 【LeetCode with Python】 Max Points on a Line
- Leetcode229: Max Points on a Line
- Leetcode 149. 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 Max Points on a Line
- leetCode 149. Max Points on a Line
- (leetcode)Max Points on a Line
- LeetCode-Max Points on a Line