Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
386 B
1
Indexable
Never
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)
Leave a Comment