399. Evaluate Division
dfs+memoization,需要用一个set记录某个点有没有作为起点使用过
python for loop的写法:
for (a, b), v in zip(equations, values):
graph[a][b] = v
graph[b][a] = 1 / v
for (x, y) in queries:
res.append(dfs(x, y, set()))
200.
Immutable Objects are of in-built datatypes like int, float, bool, string, Unicode, and tuple. In simple words, an immutable object can’t be changed after it is created.
Mutable Objects are of type Python list, Python dict, or Python set. Custom classes are generally mutable.
所以这里grid[i][j]的改变会被带到外面
用self,这样numIslands也可以access用dfs
在boundary上或者和在boundary上格子相连的格子都不需要变成x。所以只需要思路同上地标记处所有不需要变的0就行(标记#之类的)。剩下的0就是要变成x的。