Max Points on a Line
来源:互联网 发布:经济学推荐书籍 知乎 编辑:程序博客网 时间:2024/06/16 08:03
------QUESTION------
Given
------SOLUTION------
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) { float k; int counter = 0,ret = 0,tmpMax = 0; unordered_map< float,int > slopes; for(int i = 0; i < points.size(); i++){ for(int j = 0; j < points.size(); j++){ if(points[j].x==points[i].x&&points[j].y==points[i].y){ counter++; continue; } k = (float)(points[j].y-points[i].y)/(points[j].x-points[i].x); slopes[k]++; } for(unordered_map< float,int >::iterator it=slopes.begin(); it!=slopes.end();it++){ tmpMax =max(tmpMax, it->second); } ret = max(tmpMax+counter, ret); counter = 0; tmpMax = 0; slopes.clear(); } return ret; }};
0 0
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points On a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- max points on a line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- LRU Cache
- GeoGeo大数据集
- Insertion Sort List
- Sort List
- LeetCode: Remove Duplicates from Sorted Array
- Max Points on a Line
- GeoGeo Master-Slave窗口事件
- 单例与static函数
- ARMHF versus ARMEL
- Catalogue of leetcode
- Android Sensor 移植
- 红黑树系列二:红黑树的插入
- GeoGeo大图
- I2C驱动编程接口