HardRating 1930
269. Alien Dictionary
arraystringdepth-first-searchbreadth-first-searchgraphtopological-sort
解題說明
C++ 解法
複雜度分析
虛擬碼
1. Collect all unique characters, init in-degree to 0 2. For each adjacent word pair (w1, w2): a. Find first differing position j b. Add edge w1[j] -> w2[j], increment in-degree of w2[j] c. If w1 is longer prefix of w2: return "" (invalid) 3. Kahn's BFS: enqueue chars with in-degree 0, process, decrement neighbors 4. If all chars processed, return order; else return "" (cycle)