标签:str etc href def 每日一题 data data- list ble
思路:并查集 先把所有==合并,再将所有 !=查找。如果是同一个父亲就return false 。
class Solution: def equationsPossible(self, equations: ‘List[str]‘) -> ‘bool‘: fa={chr(i):chr(i) for i in range(97,125)} def find(x): if x!= fa[x]: fa[x] = find(fa[x]) return fa[x] for it in equations: if(it[1]=="="): fa[find(it[0])]=find(it[3]) for it in equations: if (it[1] == "!"): if(find(it[3])==find(it[0])): return False return True
标签:str etc href def 每日一题 data data- list ble
原文地址:https://www.cnblogs.com/2014slx/p/13072164.html