Easy Python codes which beet over 85%


  • 0
    E

    Easy python code using stack.

    def sumOfLeftLeaves(self, root):
            """
            :type root: TreeNode
            :rtype: int
            """
            row = [root]
            r = 0
            while row:
                currentNode = row.pop()
                if currentNode<>None:
                    row.append(currentNode.left)
                    row.append(currentNode.right)
                    if currentNode.left<>None and currentNode.left.left==None and currentNode.left.right ==None:
                        r = currentNode.left.val+r
            return r

Log in to reply
 

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