Symmetric Tree - Leetcode 101 - Python

  Рет қаралды 39,447

NeetCodeIO

NeetCodeIO

Күн бұрын

Пікірлер: 45
@Endericos
@Endericos 7 ай бұрын
Also iterative BFS version in Python in case anyone needs from collections import deque class Solution: def isSymmetric(self, root: Optional[TreeNode]) -> bool: q = deque([(root, root)]) while q: left, right = q.popleft() if not left and not right: continue if not left or not right: return False if left.val != right.val: return False q.append((left.left, right.right)) q.append((left.right, right.left)) return True
@keeprocking3620
@keeprocking3620 8 ай бұрын
Null handling (at least in Java) for left and right nodes can be done a bit easier: if one of them is null, all we need to do is check for their equality with == operator: if (left == null || right == null) { return left == right; } Not sure if it works in python, though.
@licokr
@licokr 8 ай бұрын
It's always good to come here even when I don't find difficulties while solving the problem. I compare left.left.value and right.right.value, didn't think of comparing itself. Thanks for uploading great videos. You had me enjoy solving problems
@eshabaweja
@eshabaweja Жыл бұрын
I love how you posted this the exact same day i gave up on it when i thought . Keep going bruh you're doing awesome work
@infiniteloop5449
@infiniteloop5449 Жыл бұрын
@NeetcodeIO do you happen to have a published leetcode list for Neetcode All List? I finished the Neetcode 150 and would like to test on all of the Neetcode All questions I had not seen. Thank you for all your work and great teaching.
@energy-tunes
@energy-tunes 5 ай бұрын
Check if left subtree is equal to inverted right subtree. Done.
@linainsworth3566
@linainsworth3566 2 ай бұрын
Can you invert one sub tree and see if now both sub trees are identical? I did so and even though both sub tress are the same but doesn't look like I can just do a direct comparison of them. Something like this: def isSymmetric(root): def invertTree(root): if not root: return None root.left, root.right = root.right, root.left invertTree(root.left) invertTree(root.right) return root return root.left == invertTree(root.right)
@satwiktatikonda764
@satwiktatikonda764 Жыл бұрын
After a long gap Neet code is back
@bhabishyachaudhary3495
@bhabishyachaudhary3495 Жыл бұрын
Very well explained thank you so much👏
@tg-shyam2887
@tg-shyam2887 Жыл бұрын
was expecting you daily bro, please try to cover the past daily challenge problems, kind request🥺🥺🥺🥺🥺
@elvisgarcia1822
@elvisgarcia1822 Жыл бұрын
Hello, can someone tell me what Aplication is he using for draw? Is that a website or app?
@BurhanAijaz
@BurhanAijaz Жыл бұрын
a web extension
@elvisgarcia1822
@elvisgarcia1822 Жыл бұрын
@@BurhanAijaz which one?
@leeroymlg4692
@leeroymlg4692 Жыл бұрын
it's Paint 3D
@Vancha112
@Vancha112 Жыл бұрын
Heck yeah, thanks for the vid! ^^
@saurabhd7990
@saurabhd7990 Жыл бұрын
Yo! How was your India trip? Did you have good food? Thanks for the video.
@NeetCodeIO
@NeetCodeIO Жыл бұрын
Yeah, it was a lot of fun! But was thinking about work most of the time 😅
@sharathkumar8338
@sharathkumar8338 Жыл бұрын
@@NeetCodeIO was manager calling you??
@yang5843
@yang5843 Жыл бұрын
Welcome back
@seandean2805
@seandean2805 9 ай бұрын
why did you return dfs()?
@CHIRANJIBNANDY1
@CHIRANJIBNANDY1 5 ай бұрын
the method needs to return the boolean value
@yasarapudurgabhavani3985
@yasarapudurgabhavani3985 Жыл бұрын
Thanks!
@devanshpurwar
@devanshpurwar Жыл бұрын
bro really have good amount of money
@swarnabhkashyap5764
@swarnabhkashyap5764 10 ай бұрын
Bhai thoda mujhe bhi de de
@ABINETDEGEFA
@ABINETDEGEFA 8 ай бұрын
how dfs function accepts only one argument at the time of returning to the isSymetric function
@perelium-x
@perelium-x 8 ай бұрын
I came here to see if he had done the bfs solution. Can someone explain the bfs solution. Its kinda not straight forward (for me at least )😅😅
@pedrohenriqueleite9382
@pedrohenriqueleite9382 Жыл бұрын
why have to use val in line 15?
@kkp2174
@kkp2174 Жыл бұрын
they are two separate nodes held in two separate locations in memory, comparing the nodes by "reference" (their memory location) they are not the same, but using comparison by "value" they are equal.
@chandankhuntia7017
@chandankhuntia7017 Жыл бұрын
❤❤❤❤❤
@cubingmachine1968
@cubingmachine1968 Жыл бұрын
I traverse the tree and check the returning array was a palindrome
@thevinarokiarajl2149
@thevinarokiarajl2149 Жыл бұрын
195th testcase in leetcode didnt pass. Expected is False but getting True. Tree is [1,2,2,2,null,2] for ref..
@Jack-ss4re
@Jack-ss4re 10 ай бұрын
Is that easy? Ffs
@SadgeZoomer
@SadgeZoomer Жыл бұрын
Первонахи жрут какахи
@Gribozhuy
@Gribozhuy Жыл бұрын
У меня такая задача была в Тинькове на собесе, оказывается она и тут есть.
@GorgeousPuree
@GorgeousPuree 2 ай бұрын
@@Gribozhuy на какую должность?
@yasarapudurgabhavani3985
@yasarapudurgabhavani3985 Жыл бұрын
Thanks!
@krateskim4169
@krateskim4169 Жыл бұрын
Welcome back
@yasarapudurgabhavani3985
@yasarapudurgabhavani3985 Жыл бұрын
Thanks!
@yasarapudurgabhavani3985
@yasarapudurgabhavani3985 Жыл бұрын
Thanks!
@pkyadav6230
@pkyadav6230 Жыл бұрын
Kuch Mujhe bhee dede
@yipyiphooray339
@yipyiphooray339 Жыл бұрын
​@@pkyadav6230lmaoo
@thevinarokiarajl2149
@thevinarokiarajl2149 Жыл бұрын
bro stole his mom's credit card
@yasarapudurgabhavani3985
@yasarapudurgabhavani3985 Жыл бұрын
Thanks!
@yasarapudurgabhavani3985
@yasarapudurgabhavani3985 Жыл бұрын
Thanks!
Design Hashmap - Leetcode 706 - Python
14:30
NeetCodeIO
Рет қаралды 35 М.
Rotating the Box - Leetcode 1861 - Python
15:14
NeetCodeIO
Рет қаралды 6 М.
Кто круче, как думаешь?
00:44
МЯТНАЯ ФАНТА
Рет қаралды 5 МЛН
Players push long pins through a cardboard box attempting to pop the balloon!
00:31
How Many Balloons To Make A Store Fly?
00:22
MrBeast
Рет қаралды 92 МЛН
Hoodie gets wicked makeover! 😲
00:47
Justin Flom
Рет қаралды 133 МЛН
Is Coding still worth it in 2024? (as an ex-Google programmer)
13:36
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 147 М.
I Solved 100 LeetCode Problems
13:11
Green Code
Рет қаралды 245 М.
Top 7 Algorithms for Coding Interviews Explained SIMPLY
21:22
Codebagel
Рет қаралды 442 М.
How to solve (almost) any binary tree coding problem
4:20
Inside code
Рет қаралды 187 М.
Find Duplicate Subtrees - Leetcode 652 - Python
14:33
NeetCodeIO
Рет қаралды 20 М.
Count Unguarded Cells in the Grid - Leetcode 2257 - Python
17:14
Кто круче, как думаешь?
00:44
МЯТНАЯ ФАНТА
Рет қаралды 5 МЛН