My python code,
class Solution:
def minCostConnectPoints(self, points: List[List[int]]) -> int:
# Creating Adjacency List
n = len(points)
adjList = {i : [] for i in range(n)}
for i in range(n):
x1, y1 = points[i]
for j in range(i + 1, n):
x2, y2 = points[j]
distance = abs(x1 - x2) + abs(y1 - y2)
adjList[i].append([dist, j])
adjList[j].append([dist, i])
# Prim's Algorithm
res = 0
visited = set()
minH = [[0, 0]]
while len(visited) < n:
x = heapq.heappop(minH)
distance = x[0]
i = x[1]
if i in visited:
continue
res += distance
visited.add(i)
for neighborDistance, neighbor in adjList[i]:
if neighbor not in visited:
heapq.heappush(minH, [neighborDistance, neighbor])
return res
produces the following error:
TypeError: unsupported operand type(s) for +=: ‘int’ and ‘builtin_function_or_method’
res += distance
I can’t figure out why distance isn’t treated as an integer