Simple brute force but accepted

  • 0
    class Solution(object):
        def findLeaves(self, root):
            :type root: TreeNode
            :rtype: List[List[int]]
            leaves = []
            def popLeaf(root,collect):
                if root:
                    if root.left is None and root.right is None:
                        return None
                    root.left  = popLeaf(root.left, collect)
                    root.right = popLeaf(root.right, collect)
                return root
            while root:
                collect = []
                root = popLeaf(root,collect)
            return leaves

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.