Skip to content

Commit

Permalink
Time: 190 ms (58.86%), Space: 35 MB (50.47%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
hovanhoa committed Oct 18, 2023
1 parent 634dfa4 commit 481198a
Showing 1 changed file with 1 addition and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
class Solution:
def goodNodes(self, root: TreeNode) -> int:
return self.getGoodNodes(root, float("-inf"))

def getGoodNodes(self, root: TreeNode, newMax: int) -> int:
if not root:
return 0

newMax = max(newMax, root.val)
return (1 if root.val >= newMax else 0) + self.getGoodNodes(root.left, newMax) + self.getGoodNodes(root.right, newMax)

0 comments on commit 481198a

Please sign in to comment.