LeetCode Merge Two Binary Trees Solution Explained - Java

  Рет қаралды 50,696

Nick White

Nick White

Күн бұрын

The Best Place To Learn Anything Coding Related - bit.ly/3MFZLIZ
Join my free exclusive community built to empower programmers! - www.skool.com/...
Preparing For Your Coding Interviews? Use These Resources
--------------------
(My Course) Data Structures & Algorithms for Coding Interviews - thedailybyte.d...
AlgoCademy - algocademy.com...
Daily Coding Interview Questions - bit.ly/3xw1Sqz
10% Off Of The Best Web Hosting! - hostinger.com/...
Follow Me on X/Twitter - x.com/nickwhit...
Follow My Instagram - / nickwwhite
Other Social Media
----------------------------------------------
Discord - / discord
Twitch - / nickwhitettv
TikTok - / nickwhitetiktok
LinkedIn - / nicholas-w-white
Show Support
------------------------------------------------------------------------------
Patreon - / nick_white
PayPal - paypal.me/nick....
Become A Member - / @nickwhite
#coding #programming #softwareengineering

Пікірлер: 26
@basedonprinciple
@basedonprinciple 4 жыл бұрын
Thanks for the tip about doing the 40 tree problems at the end.
@ConwellConwell
@ConwellConwell Жыл бұрын
Nick helped code 911 and grinder
@Kitchen-Raccoon4572
@Kitchen-Raccoon4572 11 ай бұрын
Bring back this Nick White. The cool chill one that just helps out
@sadmanabedin1203
@sadmanabedin1203 4 жыл бұрын
got the logic and solved the problem just after 3:27. thanks bro.
@muscle_coder
@muscle_coder Жыл бұрын
Great Work bro Can you make a basic lecture on Binary Tree explaining the traversals with dry run in Trees ?
@abhaypatil2000
@abhaypatil2000 4 жыл бұрын
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.
@mdaminulhoque1707
@mdaminulhoque1707 2 жыл бұрын
line 23, it should be t1.right = mergeTrees(t1.right, t2.right);
@snake1625b
@snake1625b 2 жыл бұрын
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
@jay31415
@jay31415 4 жыл бұрын
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".
@Emmanuel-px9lk
@Emmanuel-px9lk 5 жыл бұрын
Very clear. Thanks
@xbeta84
@xbeta84 4 жыл бұрын
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
@boshiij3449
@boshiij3449 4 жыл бұрын
This is good but the interviewer might ask to reduce space by merging in-place instead of creating a new binary tree. Good to know and understand both though.
@noctua7771
@noctua7771 Жыл бұрын
You are brilliant good sir!
@TheodoreRavindranath
@TheodoreRavindranath 3 жыл бұрын
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!!
@bigblue82
@bigblue82 3 жыл бұрын
Agreed! When I first attempted this I assumed (wrongly, but based on experience) that the input trees should not be mutated. So I created an entire new tree and left the input trees untouched which made my solution more complicated. This one is far more simple, but it mutates t1 which feels so gross to me.
@vishwajeetbarve6538
@vishwajeetbarve6538 3 жыл бұрын
Clean and Simple
@DEEPAKGOYALnullRA
@DEEPAKGOYALnullRA 4 жыл бұрын
why this problem is in easy level its looking too difficult man
@botdot7226
@botdot7226 4 жыл бұрын
Yeah I agree. My theory is that it rates the problems based on the % accepted rate. As you can see 136k/200k submissions passed meaning ~68% completed this problem. However, this is problem 617 meaning that only really dedicated users will have attempted this problem as fewer people will have likely made it past the first couple questions. Therefore, in this 200k is likely to be very experienced coders so the difficulty rating is misleading.
@spectermakoto9029
@spectermakoto9029 4 жыл бұрын
you have to really understand cs fundamentals not a difficult problem if you do have problems i recommend you brush up on trees and recursion
@jugsma6676
@jugsma6676 4 жыл бұрын
This is just the DFS traversal of the tree.
@sarf_alam
@sarf_alam 3 жыл бұрын
wait why is he not indian😂😂?
@isanrodrigueztrimino6701
@isanrodrigueztrimino6701 Жыл бұрын
28 of January of 2023. Leetcode hasn't fix that yet
@cocoarecords
@cocoarecords 4 жыл бұрын
ty
@eshagupta9407
@eshagupta9407 4 жыл бұрын
You rock, Thanks!
@spinacker16
@spinacker16 4 жыл бұрын
it's soooo easy =( But I cant solve even that problem... what's wrong with me GOD DAMN
@cartooncartel6493
@cartooncartel6493 3 жыл бұрын
I hate it when he says that
Merge Two Binary Trees - Leetcode 617
11:57
NeetCode
Рет қаралды 56 М.
LeetCode Check Completeness of a Binary Tree Explained - Java
6:35
Walking on LEGO Be Like... #shorts #mingweirocks
00:41
mingweirocks
Рет қаралды 7 МЛН
Players push long pins through a cardboard box attempting to pop the balloon!
00:31
Twin Telepathy Challenge!
00:23
Stokes Twins
Рет қаралды 65 МЛН
This Algorithm is 1,606,240% FASTER
13:31
ThePrimeagen
Рет қаралды 851 М.
Merge Two Binary Trees | Live Coding with Explanation | Leetcode - 617
25:53
Algorithms Made Easy
Рет қаралды 6 М.
I Got Rejected (again)
9:43
Nick White
Рет қаралды 205 М.
Self Taught Programmers... Listen Up.
11:21
Nick White
Рет қаралды 1,1 МЛН
3 Types of Algorithms Every Programmer Needs to Know
13:12
ForrestKnight
Рет қаралды 498 М.
Coding Interviews Be Like Pt. 3
3:02
Nicholas T.
Рет қаралды 403 М.
Binary Trees - Data Structures Explained
10:18
Aaron Jack
Рет қаралды 139 М.
Walking on LEGO Be Like... #shorts #mingweirocks
00:41
mingweirocks
Рет қаралды 7 МЛН