Max Points on a Line [leetcode]
来源:互联网 发布:帝国cms html5模板 编辑:程序博客网 时间:2024/05/08 09:10
思路:对每个点,记录<斜率, 点的个数>对
因为一条直线可以由点+斜率决定,所以相同斜率必在同一条直线上
int maxPoints(vector<Point> &points) { int n = points.size(); int maxRes = 0; for (int i = 0; i < n; i++) { int samePoint = 0, x0 = 0, curMax = 0; map<double, int> kMap; for (int j = 0; j < n; j++) { if (points[i].x == points[j].x && points[i].y == points[j].y) samePoint++; else if (points[i].x == points[j].x) curMax = max(curMax, ++x0); else { double k = (points[i].y - points[j].y + 0.0) / (points[i].x - points[j].x); curMax = max(curMax, ++kMap[k]); } } maxRes = max(curMax + samePoint, maxRes); } return maxRes; }
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
- Netflix on Linux:如何在Linux上使用Netflix以及为什么在Linux上使用Netflix怎么就这么难
- svn出现问题E220001: Item is not readable
- grep命令(常用:与管道搭配,筛选出带某个关键词的输出)
- java运算符表达式与语句
- hdu2095 find your present (2)
- Max Points on a Line [leetcode]
- 空格在Html中的表示方法( 含义)
- java判断与循环语句
- hdu2098
- java数组定义及使用
- 115个Java面试题及回答
- 通过@Value注解读取.properties配置内容 (续)
- 从头学起
- SpringMVC EL 表达式不起作用