mirror of
https://github.com/prdlk/leetcode.git
synced 2026-11-02 21:22:43 +00:00
docs(docs): add Approach diagrams and Explanation sections to LeetCode problem documentation
This commit is contained in:
1 parent
b8c779903f
commit
23eb71d387
19 files changed
+439
No files matched your search
@@ -29,6 +29,26 @@ sidebar:
|
||||
- The number of nodes in the tree is in the range [0, 100].
|
||||
- `-100 <= Node.val <= 100`
|
||||
|
||||
## Approach
|
||||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
S(["rightSideView(root)"]) --> I["res = [], q = deque([root])"]
|
||||
I --> W{"q non-empty?"}
|
||||
W -- no --> E(["return res"])
|
||||
W -- yes --> L["rightSide = None, qLen = len(q) — qLen freezes the current level's size"]
|
||||
L --> F{"more i in range(qLen)?"}
|
||||
F -- no --> V{"rightSide is not None?"}
|
||||
V -- yes --> A["res.append(rightSide.val) — the last real node popped on this level is the rightmost"]
|
||||
A --> W
|
||||
V -- no --> W
|
||||
F -- yes --> P["node = q.popleft()"]
|
||||
P --> N{"node is not None?"}
|
||||
N -- no --> F
|
||||
N -- yes --> C["rightSide = node, q.append(node.left), q.append(node.right)"]
|
||||
C --> F
|
||||
```
|
||||
|
||||
## Solution
|
||||
|
||||
```py
|
||||
@@ -62,3 +82,7 @@ class Solution:
|
||||
|
||||
return res
|
||||
```
|
||||
|
||||
## Explanation
|
||||
|
||||
<YouTube id="d4zLyf32e3I" title="Binary Tree Right Side View - Breadth First Search - Leetcode 199" />
|
||||
Reference in new issue
Block a user