File tree Expand file tree Collapse file tree 2 files changed +31
-3
lines changed
binary-tree-level-order-traversal Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Original file line number Diff line number Diff line change 1+ """
2+ ๋ฌธ์ ์ค๋ช
:
3+ There is a new alien language which uses the latin alphabet.
4+ However, the order among letters are unknown to you.
5+ You receive a list of non-empty words from the dictionary,
6+ where words are sorted lexicographically by the rules of this new language.
7+ Derive the order of letters in this language.
8+
9+ Conditions:
10+ - You may assume all letters are in lowercase
11+ - At first different letter, if the letter in s precedes the letter in t in the given list order, then the dictionary order of s is less than t
12+ - The dictionary is invalid, if string a is prefix of string b and b is appear before a
13+ - If the order is invalid, return an empty string
14+ - There may be multiple valid order of letters, return the smallest in normal lexicographical order
15+ - The letters in one string are of the same rank by default and are sorted in Human dictionary order
16+
17+ Time Complexity:
18+ -
19+
20+ Space Complexity:
21+ -
22+ """
Original file line number Diff line number Diff line change 1010- ๊ฒฐ๊ณผ ๋ฆฌ์คํธ๋ ๋ชจ๋ ๋
ธ๋์ ๊ฐ์ ์ ์ฅํจ
1111
1212ํ์ด๋ฐฉ๋ฒ:
13- 1. queue์ BFS๋ฅผ ํ์ฉํ์ฌ ๋ ๋ฒจ ์์๋ก ๋
ธ๋๋ฅผ ์ํ
14- 2. ๊ฐ ๋ ๋ฒจ์ ๋
ธ๋๋ค์ ๋ณ๋์ ๋ฆฌ์คํธ๋ก ๋ชจ์์ ๊ฒฐ๊ณผ์ ์ถ๊ฐ
15- 3. ๊ฐ ๋
ธ๋๋ฅผ ์ฒ๋ฆฌํ ๋ ๊ทธ ๋
ธ๋์ ์์๋ค์ ํ์ ์ถ๊ฐํ์ฌ ๋ค์ ๋ ๋ฒจ๋ก ๋์ด๊ฐ
13+ 1. ๋ฃจํธ๊ฐ ์์ผ๋ฉด ๋น ๋ฆฌ์คํธ ๋ฐํ
14+ 2. ํ์ ๋ฃจํธ ๋ฃ๊ธฐ
15+ 3. while ํ๊ฐ ๋น ๋๊น์ง:
16+ - ํ์ฌ ๋ ๋ฒจ์ ๋
ธ๋ ๊ฐ์ ์ ์ฅ
17+ - ๊ทธ ๊ฐ์๋งํผ ๋
ธ๋๋ฅผ ๊บผ๋
18+ - ๋
ธ๋์ ๊ฐ ์ ์ฅ
19+ - ์์์ด ์์ผ๋ฉด ํ์ ์ถ๊ฐ
20+ - ๊ฒฐ๊ณผ์ ํ์ฌ ๋ ๋ฒจ์ ์ถ๊ฐ
1621"""
1722# Definition for a binary tree node.
1823# class TreeNode:
@@ -44,3 +49,4 @@ def levelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:
4449 result .append (current_level )
4550
4651 return result
52+
You canโt perform that action at this time.
0 commit comments