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
@keeprocking36208 ай бұрын
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.
@licokr8 ай бұрын
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 Жыл бұрын
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 Жыл бұрын
@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-tunes5 ай бұрын
Check if left subtree is equal to inverted right subtree. Done.
@linainsworth35662 ай бұрын
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 Жыл бұрын
After a long gap Neet code is back
@bhabishyachaudhary3495 Жыл бұрын
Very well explained thank you so much👏
@tg-shyam2887 Жыл бұрын
was expecting you daily bro, please try to cover the past daily challenge problems, kind request🥺🥺🥺🥺🥺
@elvisgarcia1822 Жыл бұрын
Hello, can someone tell me what Aplication is he using for draw? Is that a website or app?
@BurhanAijaz Жыл бұрын
a web extension
@elvisgarcia1822 Жыл бұрын
@@BurhanAijaz which one?
@leeroymlg4692 Жыл бұрын
it's Paint 3D
@Vancha112 Жыл бұрын
Heck yeah, thanks for the vid! ^^
@saurabhd7990 Жыл бұрын
Yo! How was your India trip? Did you have good food? Thanks for the video.
@NeetCodeIO Жыл бұрын
Yeah, it was a lot of fun! But was thinking about work most of the time 😅
@sharathkumar8338 Жыл бұрын
@@NeetCodeIO was manager calling you??
@yang5843 Жыл бұрын
Welcome back
@seandean28059 ай бұрын
why did you return dfs()?
@CHIRANJIBNANDY15 ай бұрын
the method needs to return the boolean value
@yasarapudurgabhavani3985 Жыл бұрын
Thanks!
@devanshpurwar Жыл бұрын
bro really have good amount of money
@swarnabhkashyap576410 ай бұрын
Bhai thoda mujhe bhi de de
@ABINETDEGEFA8 ай бұрын
how dfs function accepts only one argument at the time of returning to the isSymetric function
@perelium-x8 ай бұрын
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 Жыл бұрын
why have to use val in line 15?
@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 Жыл бұрын
❤❤❤❤❤
@cubingmachine1968 Жыл бұрын
I traverse the tree and check the returning array was a palindrome
@thevinarokiarajl2149 Жыл бұрын
195th testcase in leetcode didnt pass. Expected is False but getting True. Tree is [1,2,2,2,null,2] for ref..
@Jack-ss4re10 ай бұрын
Is that easy? Ffs
@SadgeZoomer Жыл бұрын
Первонахи жрут какахи
@Gribozhuy Жыл бұрын
У меня такая задача была в Тинькове на собесе, оказывается она и тут есть.