This is how I did it, in Python. I'm not sure what the overall time complexity is considering there are two O(n) operations for every DFS call where nums is not empty. class Solution: def constructMaximumBinaryTree(self, nums: List[int]) -> Optional[TreeNode]: if not nums: return max_num = max(nums) max_index = nums.index(max_num) root = TreeNode(max_num) root.left = self.constructMaximumBinaryTree(nums[:max_index]) root.right = self.constructMaximumBinaryTree(nums[max_index+1:]) return root
@abdulmutaalazhar82358 ай бұрын
Hi, really nice explanation. Thank you btw, which drawing pad and drawing software are you using ?
@nikoo288 ай бұрын
that is GoodNotes 6
@tanishkaagarwal67507 ай бұрын
Wonderful explanation
@AniketWaghmare-qi7wmАй бұрын
Hey Nikhil Please Make Video On leetcode Question Number 1448. count Good Nodes in Binary Tree using java
@subee1289 ай бұрын
Thanks
@ritikanand3425 Жыл бұрын
Great Explanation
@nikoo28 Жыл бұрын
Glad you liked it
@rjarora5 ай бұрын
Bhai brute force bata dia ye to
@nikoo285 ай бұрын
What do you mean?
@athirap25294 ай бұрын
@@nikoo28 I think he meant it's a brute force solution