Skip to content

Commit 47a4853

Browse files
authored
Update erect-the-fence.py
1 parent 216df12 commit 47a4853

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Python/erect-the-fence.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ def outerTrees(self, points):
1414
def ccw(A, B, C):
1515
return (B[0]-A[0])*(C[1]-A[1]) - (B[1]-A[1])*(C[0]-A[0])
1616

17-
if len(points) <= 3:
18-
return points
1917
hull = []
2018
points.sort()
2119
for i in itertools.chain(xrange(len(points)), reversed(xrange(len(points)-1))):
2220
while len(hull) >= 2 and ccw(hull[-2], hull[-1], points[i]) < 0:
2321
hull.pop()
2422
hull.append(points[i])
25-
hull.pop()
23+
if len(hull) >= 2:
24+
hull.pop()
25+
for i in xrange(1, (len(hull)+1)//2):
26+
if hull[i] != hull[-1]:
27+
break
28+
hull.pop()
2629
return hull

0 commit comments

Comments
 (0)