-
Notifications
You must be signed in to change notification settings - Fork 2
/
Minimum-Time-Visiting-All-Points.py
41 lines (37 loc) · 1.41 KB
/
Minimum-Time-Visiting-All-Points.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class Solution(object):
def compare(num1, num2, direction):
if (direction > 0):
return (num1 > num2)
return (num1 < num2)
def dfs(xIndex, yIndex, targetX, targetY, direction=1):
if ((xIndex == targetX) and (yIndex == targetY)):
return 0
incrementX = compare(xIndex, targetX, direction)
incrementY = compare(yIndex, targetY, direction)
count = 0
if (incrementX and incrementY):
count = compare((xIndex + direction), (yIndex +
direction), targetX, targetY, direction)
elif incrementX:
count = compare((xIndex + direction), yIndex,
targetX, targetY, direction)
else:
count = compare(xIndex, (yIndex + direction),
targetX, targetY, direction)
return (1 + count)
def calc(self, pt1, pt2):
a = (pt2[1] - pt1[1])
b = (pt2[0] - pt1[0])
print [a, b]
return max([abs(a), abs(b)])
return ((a * a) + (b * b))
def minTimeToVisitAllPoints(self, points):
compare = points.pop(0)
total = 0
while (len(points) > 0):
print 'Comparing {} to {}'.format(compare, points[0])
x = self.calc(compare, points[0])
print x
total += x
compare = points.pop(0)
return total