Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit90ebfb1

Browse files
authored
Update minimum-number-of-lines-to-cover-points.py
1 parent489a02c commit90ebfb1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

‎Python/minimum-number-of-lines-to-cover-points.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def minimumLines(self, points):
1414
defgcd(a,b):# Time: O(log(a + b))
1515
whileb:
1616
a,b=b,a%b
17-
returna
17+
returnabs(a)
1818

1919
defpopcount(x):
2020
result=0
@@ -35,6 +35,11 @@ def ceil_divide(a, b):
3535
a,b,c= (y2-y1),-(x2-x1),x1*(y2-y1)-y1*(x2-x1)
3636
g=gcd(gcd(a,b),c)
3737
a,b,c=a//g,b//g,c//g
38+
forxin (a,b,c):
39+
ifx!=0:
40+
ifx<0:
41+
a,b,c=-a,-b,-c
42+
break
3843
lookup[(a,b,c)].add((x1,y1))
3944
lookup[(a,b,c)].add((x2,y2))
4045
lines= [lforl,pinlookup.iteritems()iflen(p)>2]# filter to improve complexity

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp