Untitled
Anonymous
plain_text
05/10/2024 10:20 PM
516 B
11
Indexable
class Solution(object):
def goodNodes(self, root):
"""
:type root: TreeNode
:rtype: int
"""
def count(node, rmax):
if node:
rmax = max(rmax, node.val)
return (1 if node.val >= rmax else 0) + count(node.left, rmax) + count(node.right, rmax)
return 0
return count(root, root.val)Editor is loading...
Leave a Comment