Binary Tree Right Side View: Leetcode 75 in Tamil (தமிழ்)

  Рет қаралды 94

Indic Coder

Indic Coder

Күн бұрын

Пікірлер: 4
@karanm6077
@karanm6077 Ай бұрын
That's a very simple explanation bro. Keep up the good work. To print the left side view: 1. Append the first element value in the tree to the result array before looping. 2. Pop the first element in the loop. def left_view(root): lv = []; q = [root] if(root == None): return [] while q: lv.append(q[0].value) for _ in range(len(q)): node = q.pop(0); if(node.left): q.append(node.left) if(node.right): q.append(node.right) return lv
@indiccoder
@indiccoder Ай бұрын
Yes bro, perfect logic! 😁
@indiccoder
@indiccoder Ай бұрын
Python Solution: class Solution: def rightSideView(self, root: Optional[TreeNode]) -> List[int]: # Edge Case - Tree is empty if root == None: return [] # Init rv to empty and q to root node rv = [] q = [root] while q: # Append last node value to right view rv.append(q[-1].val) # For each node in current level add children to q for _ in range(len(q)): node = q.pop(0) if node.left: q.append(node.left) if node.right: q.append(node.right) # Return the Right Side View List return rv
@indiccoder
@indiccoder Ай бұрын
Java Solution: class Solution { public List rightSideView(TreeNode root) { // Initialize right view list rv to empty list ArrayList rv = new ArrayList(); // If tree is empty, return empty rv list if (root == null) { return rv; } // Initialize queue with root node ArrayList q = new ArrayList(); q.add(root); // BFS while (!q.isEmpty()) { // Add the value of the last node in the queue to rv rv.add(q.get(q.size() - 1).val); // Process each node in the current level int size = q.size(); for (int i = 0; i < size; i++) { // Remove the node from the front of the queue TreeNode node = q.remove(0); // Add its children to the back of the queue if (node.left != null) { q.add(node.left); } if (node.right != null) { q.add(node.right); } } } return rv; } }
L24. Right/Left View of Binary Tree | C++ | Java
13:28
take U forward
Рет қаралды 240 М.
How to treat Acne💉
00:31
ISSEI / いっせい
Рет қаралды 108 МЛН
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН
one year of studying (it was a mistake)
12:51
Jeffrey Codes
Рет қаралды 259 М.
10.1 AVL Tree - Insertion and Rotations
43:08
Abdul Bari
Рет қаралды 1,3 МЛН
Binary Search - Search A 2D Matrix -  Leetcode 74- tamil
12:48
Algo Tamizha
Рет қаралды 2,1 М.
Binary Tree Right Side View | Live Coding with Explanation | Leetcode #199
7:06
8 TIPS to IMPROVE LOGICAL THINKING (VERY FAST)
21:58
CodingAnna
Рет қаралды 62 М.
How to treat Acne💉
00:31
ISSEI / いっせい
Рет қаралды 108 МЛН