269. Alien Dictionary

Description

Here

Intuition

Toplogical Sorting.

Pitfall

Test case 1

['z', 'z']这种就比较骚了。。。

This is the trick how it's resolved

之前先加入0值,然后queue可以加入它,但是由于child关系,始终不能进入循环

Test case 2

loop

loop 会因为父节点数或者子节点数不为零而不能进入queue,从而无法使得所有节点遍历,还是很容易解决的

Solution

results matching ""

    No results matching ""