We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ff32745 commit f594ed8Copy full SHA for f594ed8
python/0149-maximum-points-on-a-line.py
@@ -0,0 +1,19 @@
1
+class Solution:
2
+ def maxPoints(self, points: List[List[int]]) -> int:
3
+ # 1. For each pt determine if it lies on the longest line
4
+ # 2. Count all pts with same slope
5
+ # 3. Update result with max
6
+
7
+ res = 1
8
+ for i in range(len(points)):
9
+ p1 = points[i]
10
+ count = collections.defaultdict(int)
11
+ for j in range(i + 1, len(points)):
12
+ p2 = points[j]
13
+ if p2[0] == p1[0]:
14
+ slope = float("inf")
15
+ else:
16
+ slope = (p2[1] - p1[1]) / (p2[0] - p1[0])
17
+ count[slope] += 1
18
+ res = max(res, count[slope] + 1)
19
+ return res
0 commit comments