117. 填充每个节点的下一个右侧节点指针 II
BFS 层序遍历 然后每一层都用其next将该层串起来
class Solution:
def connect(self, root: 'Node') -> 'Node':
if not root:
return root
node = root
que = deque()
que.append(node)
num = 1
while que:
tmp = 0
head = Node
for _ in range(num):
head.next =que.popleft()
head = head.next
if head.left :
que.append(head.left)
tmp+=1
if head.right:
que.append(head.right)
tmp +=1
num =tmp
return root
884. 两句话中的不常见单词
两个str 先合并 ,让对其每个单词统计, 之后打一个字典,
输出数量为1 的单词
class Solution:
def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:
word1 = (s1+' '+s2).split(" ")
res = []
dic1 = defaultdict(int)
for word in word1:
dic1[word]+=1
for word in dic1 :
if dic1[word] ==1 :
res.append(word)
return res