Thankyou bro yesterdays problem explanation helped me to implement today's problem successfully
@freecourseplatformenglish2829
2 ай бұрын
Yes, after two hard problem this one was a bit easy and therapeutic. Solved it on my own.
@fancypants6062
2 ай бұрын
0:06 Yeah this was a nice chill one compared to yesterday.
@mukulorama
2 ай бұрын
you can save creating children set by running through descriptions and creating children first, then initialise root variable to null and while passing through second time, only the root would return null when fetched from the nodes{}
@ashfaqmahmud
2 ай бұрын
all i wanted from my teachers, were simple explanations on how to solve this types of problems and you gave them. due to your help it has been even easy to convert the python code to cpp as per my necessity. thanks a lot
@HimanshuTanwani
2 ай бұрын
Optimization - instead of making additional children set, we can make a dict "child_to_parent" mapping. init the root val to be random, And while loop root = child_to_parent[root] until none. You have a root with average case complexity of log n instead of O(n) everytime.
@nishant7ng
2 ай бұрын
Will maintain leetcode streak here.
@yash-uy5ym
2 ай бұрын
This was so easy. Best explanation ❤
@bishwashkumarsah171
2 ай бұрын
Haha you posted about something about inverting in linkedIn and here we are doing the same.
@dasav6724
2 ай бұрын
in fact you can check whether parent is in children in the main loop itself as we are iterating through the descriptions anyway. Saves a pass.
@vidhishah9154
2 ай бұрын
I think that wont work.
@GeetainSaar
2 ай бұрын
I tried it by myself and i got almost correct answer. And when I searched attach was completely different 😢
@pastori2672
2 ай бұрын
getting closer to 150k bro !!
@mohanedomer9081
2 ай бұрын
man you really know what are you doing , thx bro . best youtuber ever `personals opinion` !!
@arihantsinghrana2173
2 ай бұрын
Man I really love to see a video uploaded by you this early and when I need it too!! Awesome work dude!!
@pratyushthakur8478
2 ай бұрын
We needed this after yesterday to boost our confidence
@Thorffin55
2 ай бұрын
Hey, great work neetcode!! can you do me a favor and post the explanation video of #987. Struggling to solve it and there are barely any videos explaining the intuition, people are just writing the code and saying this is it!!
@MP-ny3ep
2 ай бұрын
Thank you so much for the daily leetcode
@yang5843
2 ай бұрын
Java solution for those interested: class Solution { public TreeNode createBinaryTree(int[][] descriptions) { int i = 0; Map map = new HashMap(); for (int[] d : descriptions) map.put( d[1], new TreeNode(d[1])); TreeNode root = null; for (int[] d : descriptions) { if ( !map.containsKey(d[0])) { root = new TreeNode(d[0]); map.put(d[0],root); } if ( d[2] == 1 ) map.get(d[0]).left = map.get(d[1]); else map.get(d[0]).right = map.get(d[1]); } return root; } }
@saranshthukral4021
2 ай бұрын
looks like a linked list problem
@galkk3
2 ай бұрын
my solution, same time complexity. maybe harder to read, tell me what you think: childrens = set() root = TreeNode() parents = defaultdict(list) for par, child, left in descriptions: childrens.add(child) parents[par].append([child, left]) for par, child, left in descriptions: if par not in childrens: root.val = par break def build(node): if node.val not in parents: return node for child, left in parents[node.val]: if left: node.left = build(TreeNode(child)) else: node.right = build(TreeNode(child)) return node return build(root)
@karthi7102
2 ай бұрын
PLEASE SOLVE DAILY SIR, LOVE FROM INDIA.🤗
@thebeston6710
2 ай бұрын
Second
@qulinxao
2 ай бұрын
return (h:={v:TreeNode(v)for v in set(chain(*d))}, set(setattr(h[p],['right','left'][i],h[c])for p,c,i in d), h[sum(set(p for p,_,_ in d)-set(c for __,c,__ in d))] )[-1]
Пікірлер: 25