0
点赞
收藏
分享

微信扫一扫

LCP 44. 开幕式焰火 (Python 实现)

题目:

示例 1:

示例 2:

代码:

# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None
class Solution:
    def numColor(self, root: TreeNode) -> int:
        res = set()
        def search(root):
            if not root:
                return
            res.add(root.val)
            search(root.left)
            search(root.right)
        search(root)
        return len(res)
举报

相关推荐

0 条评论