Max Points on a Line LEETCODE
来源:互联网 发布:粉笔软件下载事业单位 编辑:程序博客网 时间:2024/06/11 19:04
Max Points on a Line
Total Accepted: 289 Total Submissions: 3644Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.
/** * Definition for a point. * struct Point { * int x; * int y; * Point() : x(0), y(0) {} * Point(int a, int b) : x(a), y(b) {} * }; */ class Solution {public: int maxPoints(vector<Point> &points) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reused for each test case. map<float, int> kmap; map<float, int>::iterator it; int size = points.size(); int total = 0; int sum_cloumn = 0; if(size<=2) return size; for(int i=0;i<size;i++) { sum_cloumn = 0; int add=1; kmap.clear(); for(int j=0;j<size;j++) { if(j==i) continue; if(points[i].x==points[j].x && points[i].y==points[j].y) { add++; continue ; } float k = 0; if(points[i].x!=points[j].x) { k = (float)(points[j].y-points[i].y)/(points[j].x-points[i].x); if(kmap.find(k)!=kmap.end()) { kmap[k]++; } else { kmap[k] = 1; } }else{ sum_cloumn++; } } for(it=kmap.begin(); it!=kmap.end();it++) { if(it->second > sum_cloumn) sum_cloumn = it->second; } sum_cloumn += add; if(sum_cloumn > total) total = sum_cloumn; } return total; } };
- 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
- 解析表达式
- 汇编中数组的加法运算-包含进位
- java学习08-getter & setter
- [Ant][StartWithAnt] 第七章 Ant扩展包ant-contrib的使用
- 小馋猫所感
- Max Points on a Line LEETCODE
- SQL Server2008 无法连接到 local
- IOS-app上线准备工作
- OpenCV_图像元素处理常用函数
- jQuery Mobile入门教程——主题的使用和定制
- 递归函数求二进制
- MTM动画教程学习笔记1【第六章 边界和摩擦力】
- 让程序员设计界面的后果
- [安卓破解]CloudSEE,中维科技,2.6.3破解版本