Skip to content

Commit 216df12

Browse files
authored
Update erect-the-fence.py
1 parent 0bdc85a commit 216df12

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Python/erect-the-fence.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ 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
1719
hull = []
1820
points.sort()
19-
for i in itertools.chain(xrange(len(points)), reversed(xrange(len(points)))):
21+
for i in itertools.chain(xrange(len(points)), reversed(xrange(len(points)-1))):
2022
while len(hull) >= 2 and ccw(hull[-2], hull[-1], points[i]) < 0:
2123
hull.pop()
2224
hull.append(points[i])
23-
return list(set(map(tuple, hull)))
25+
hull.pop()
26+
return hull

0 commit comments

Comments
 (0)