Count Good Nodes in Binary Tree - Leetcode 1448 - Trees (Python)

  Рет қаралды 1,870

Greg Hogg

Greg Hogg

Күн бұрын

Пікірлер: 7
@GregHogg
@GregHogg 4 ай бұрын
Master Data Structures & Algorithms For FREE at AlgoMap.io!
@siddhantkumar9492
@siddhantkumar9492 7 ай бұрын
Thanks for the great explanation! Just to add on, this question can also be done by using any of the 3 traversal techniques, preorder, postorder or inorder and keeping a track of the max at each node. def dfs(root, maxval): if not root: return 0 left = dfs(root.left, max(maxval, root.val)) right = dfs(root.right, max(maxval, root.val)) res = left+right if root.val >= maxval: res+=1 return res return dfs(root, root.val)
@GregHogg
@GregHogg 7 ай бұрын
Yes that's a great point, totally true. Thanks so much for the kind words :)
@JSH1994
@JSH1994 2 ай бұрын
please keep solving leetcode questions.. your explanations are great
@philipbrujic4728
@philipbrujic4728 4 ай бұрын
Good video
@gingerjiang666
@gingerjiang666 3 ай бұрын
What is the reason you solve it iteratively instead recursively? Can you explain it?
@ShahriyarRzayev
@ShahriyarRzayev 2 ай бұрын
For me, the iterative approach is easier to understand than the recursive one, and most of the other videos explain using the recursive approach. Maybe this was the reason to record the video to show an alternative to the recursive option.
Path Sum - Leetcode 112 - Trees (Python)
4:24
Greg Hogg
Рет қаралды 3 М.
Rotting Oranges - Leetcode 994 - Graphs (Python)
16:09
Greg Hogg
Рет қаралды 3,5 М.
How to Fight a Gross Man 😡
00:19
Alan Chikin Chow
Рет қаралды 17 МЛН
How Many Balloons To Make A Store Fly?
00:22
MrBeast
Рет қаралды 149 МЛН
Players push long pins through a cardboard box attempting to pop the balloon!
00:31
Diameter of Binary Tree - Leetcode 543 - Trees (Python)
11:16
ALL NODES DISTANCE K IN BINARY TREE | PYTHON | LEETCODE # 863
15:41
Cracking FAANG
Рет қаралды 8 М.
Pacific Atlantic Water Flow - Leetcode 417 - Graphs (Python)
17:10
Lowest Common Ancestor of a binary tree | Leetcode #236
17:29
Clone Graph - Leetcode 133 - Graphs (Python)
13:38
Greg Hogg
Рет қаралды 3,9 М.
How to Fight a Gross Man 😡
00:19
Alan Chikin Chow
Рет қаралды 17 МЛН