LeetCode - 114. Flatten Binary Tree to Linked List | Day 14 May Challenge
Aditya Mahajan
Problem: https://leetcode.com/problems/flatten-binary-tree-to-linked-list/ Code Link: https://github.com/skystone1000/Coding-Problems/tree/master/Leet%20Code/May%20Challenge%202021
May Challenge 2021 - Day 14 114. Flatten Binary Tree to Linked List
TIMESTAMPS 0:00 Intro 0:20 Question 0:41 Examples 1:39 Approach 1 - Recursive 4:32 Approach 1 - Code 6:38 Approach 2 - Iterative 7:43 Approach 2 - Code 9:36 Approach 3 - Morris traversal 11:10 Approach 3 - Code
When we start to think for the solution we need to rewire the nodes such that all nodes point to the right* pointers. And we know when we have rewiring in trees then PostOrder Traversal is the best as first we traverse the Left Right Root i.e. before doing anything to the root our processing for children is already done. But now if we look then in our case we have to make all nodes point to the right child so we can tweak the Post Order traversal by reversing it so we traverse. Right Left Root. This helps in our solution. So we can solve this problem with three Methods 1) Recursive approach 2) Iterative approach (Using Stack) 3) Morris Traversal (Efficient)
š Social Media š
š LinkedIn: https://www.linkedin.com/in/adityamahajan123/ š GitHub: https://github.com/skystone1000/ šø Instagram: https://www.instagram.com/skystone1000/ š Chess.com : https://www.chess.com/member/skystone1000 ā Discord Server: https://discord.gg/ZPWzT5QWDC
ā” Please leave a LIKE and SUBSCRIBE for more content! ā”
ā Tags ā
- Aditya Mahajan
ā Hashtags ā #leetcode #114Leetcode ... https://www.youtube.com/watch?v=zbe3R19mzO8
76785219 Bytes