Flatten a Linked List (Leetcode 114)
Problem Link: https://leetcode.com/problems/flatten-binary-tree-to-linked-list/
class Solution:
def flatten(self, root: Optional[TreeNode]) -> None:
if(root is None):
return None
l=self.flatten(root.left)
r=self.flatten(root.right)
if(l is not None):
temp=l
while(temp.right is not None):
temp=temp.right
temp.right=r
root.right=l
else:
root.right=r
return root
PreviousCount Nodes Equal to Average of Subtree (Leetcode 2265)NextConvert a Sorted Array into a Binary Search Tree(BST) (Leetcode 108)
Last updated