all elements in two binary search trees leetcode | leetcode 1305 | bst

preview_player
Показать описание


#BST #Inorder #Recursive #Iterative #AllElementsInTwoBST #BinaryTree #Coding #Programming #Interview #Practice #Leetcode #Medium #1305 #Algorithm #DataStructure #Java #Preparation #NG #nickode #CookCodeTravel #CCT
Рекомендации по теме
Комментарии
Автор

Nice approach 🙂

Which software you use to draw and explanation ?

AmandeepSingh-otst
Автор

Very helpful, I was asked this by facebook and failed hopefully I get it next time

CertifiedDeadMemes
Автор

I am following your leetcode series regularly, if you improve your writing as more visible it would be grateful because your approach is always nice

saravanan
Автор

hello sir i just want to say that you should solve the problem in a more efficient way. because in this question a better solution exists that is of O(2n). your's is exactly like we used to merge in merge sort so the time complexity is O(2n + 2n). hope you consider this suggestion.

pleasesirmorevideos
Автор

List<Integer> res=new ArrayList();
public List<Integer> getAllElements(TreeNode root1, TreeNode root2) {
if(root1!=null)
getInorder(root1);
if(root2!=null)
getInorder(root2);
Collections.sort(res);
return res;
}

private void getInorder(TreeNode root){
if(root.left==null && root.right==null){
res.add(root.val);
return;
}
if(root.left!=null)
getInorder(root.left);
res.add(root.val);
if(root.right!=null)
getInorder(root.right);
}

praveenj
join shbcf.ru