Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5047f1d

Browse files
Create README.md
1 parent 344d0af commit 5047f1d

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

‎day-22/README.md‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Day - 22
2+
## ⭐️ Symmetric Tree – 22.1
3+
### 🔗 Problem
4+
5+
[LeetCode #101 – Symmetric Tree](https://leetcode.com/problems/symmetric-tree/)
6+
7+
### 🧠 Core Idea
8+
9+
A tree is symmetric if it is a mirror of itself, which means the left subtree is a mirror reflection of the right subtree. We compare nodes in pairs: both null implies a match, one null or unequal values implies asymmetry, otherwise we recursively check the outer pair (left.left vs right.right) and the inner pair (left.right vs right.left) to ensure full mirrored structure and values.
10+
11+
### 📊 Example
12+
13+
Input: `root = [1,2,2,3,4,4,3]`
14+
15+
Output: true
16+
17+
### ⏱️ Complexity
18+
19+
- Time: O(n) – Each node visited once
20+
21+
- Space: O(h) – Recursion stack, h = tree height
22+
23+
👉 See full code in [symmetric_tree.py](https://github.com/lyushher/LeetCode-Python-Easy-DSA/blob/main/day-22/symmetric_tree.py)
24+
25+
---
26+
27+
## ⭐️ Invert Binary Tree – 22.2
28+
### 🔗 Problem
29+
30+
[LeetCode #226 – Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree/)_
31+
32+
### 🧠 Core Idea
33+
34+
Inversion creates the mirror image of a binary tree by swapping the left and right child at every node. Using DFS, we swap children at the current node and recurse into both subtrees; an empty node returns immediately. The result is the original tree reflected across its root.
35+
36+
### 📊 Example
37+
38+
Input: `root = [4,2,7,1,3,6,9]`
39+
40+
Output: [4,7,2,9,6,3,1]
41+
42+
### ⏱️ Complexity
43+
44+
- Time: O(n) – Visit and swap at each node once
45+
46+
- Space: O(h) – Recursion stack, h = tree height
47+
48+
👉 See full code in [invert_binary_tree.py](https://github.com/lyushher/LeetCode-Python-Easy-DSA/blob/main/day-22/invert_binary_tree.py)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /