LeetCode Merge Two Binary Trees Solution Explained - Java

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


Preparing For Your Coding Interviews? Use These Resources
————————————————————

Other Social Media
----------------------------------------------

Show Support
------------------------------------------------------------------------------

#coding #programming #softwareengineering
Рекомендации по теме
Комментарии
Автор

Thanks for the tip about doing the 40 tree problems at the end.

basedonprinciple
Автор

got the logic and solved the problem just after 3:27. thanks bro.

sadmanabedin
Автор

Bring back this Nick White. The cool chill one that just helps out

Kitchen-Raccoon
Автор

Great Work bro

Can you make a basic lecture on Binary Tree explaining the traversals with dry run in Trees ?

muscle_coder
Автор

The problem you mentioned is not with leetcode. The problem is with multithreading at hardware level. Executing same program multiple times, will result in different time.

abhaypatil
Автор

This is mine, similar to yours, but I don't merge into t1 to make it more readable


def merge_trees(t1, t2):
"""
:type t1: TreeNode
:type t2: TreeNode
:rtype: TreeNode
"""


if t1 == None:
return t2
if t2 == None:
return t1
node = TreeNode(t1.val + t2.val)
node.left = merge_trees(t1.left, t2.left)
node.right = merge_trees(t1.right, t2.right)
return node

xbeta
Автор

This question is awkwardly and ambiguously worded—a pattern I've noticed in LeetCode tree questions—as evidenced by bad grammar in the first sentence. The entire question would have been better off just showing the example on its own, ditching the misleading wording, instead simply saying "do this".

jay
Автор

oh i thought you had to insert all the nodes from the right into the left tree, not add the overlapping ones. should've read the question

snakeb
Автор

line 23, it should be t1.right = mergeTrees(t1.right, t2.right);

mdaminulhoque
Автор

why this problem is in easy level
its looking too difficult man

DEEPAKGOYALnullRA
Автор

For an experienced developer, this looks scary.. because we prefer immutability, and clean copies. All this t1.val+=t2.val thereby mutating the input tree, and just grabbing some nodes off another tree and keeping them in our tree... all this looks scary!!

TheodoreRavindranath
Автор

28 of January of 2023.
Leetcode hasn't fix that yet

isanrodrigueztrimino
Автор

it's soooo easy =( But I cant solve even that problem... what's wrong with me GOD DAMN

spinacker
welcome to shbcf.ru