#LeetCode Max Points On A Line
来源:互联网 发布:手机如何申请淘宝直播 编辑:程序博客网 时间:2024/05/01 11:28
public class Solution { public int maxPoints(Point[] points) { if (points.length == 0) return 0; if (points.length == 1) return 1; int maxP = 0; int result = 0; for (int i = 0; i < points.length; i ++) { int same = 0; int ver = 0; int max = 0; Hashtable<Double, Integer> table = new Hashtable<>(); for (int j = 0; j < points.length; j ++) { if (i == j) continue; if (points[j].x == points[i].x && points[j].y == points[i].y) same++; else if (points[j].x == points[i].x && points[j].y != points[j].y) ver++; else { double k = (double)(points[j].y - points[i].y) / (double)(points[j].x - points[i].x); if (!table.containsKey(k)) { table.put(k, 1); if (max < 1) max = 1; } else { int tmp = table.get(k); tmp++; table.put(k, tmp); if (tmp > max) max = tmp; } } } maxP = (max > ver)? max + same + 1 : ver + same + 1; if (maxP > result) result = maxP; } return result; }}
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
- Android UI控件详解-CheckBox(多选框)
- HDU 1969 Pie
- 让Source Insight支持ARM汇编.S文件关键字高亮,函数支持
- Hbase编程入门之MapReduce
- Mapreduce求TopK最大值
- #LeetCode Max Points On A Line
- 【Deep Learning】Deep Learning 教程翻译
- Codeforces 392B Tower of Hanoi(DP)
- 李振杰:腾讯入股京东=京东引狼入室
- 周报(第一周)
- redis python操作 string integer
- 指针与数组
- 堆排序【自己的理解】
- C语言基础---const常指针的使用