Sum of Left Leaves (Leetcode 404)
Problem Link: https://leetcode.com/problems/sum-of-left-leaves/
class Solution:
def sumOfLeftLeaves(self, root: Optional[TreeNode]) -> int:
global ans
ans=0
def fun(root):
global ans
if(root is None):
return 0
if(root.left is not None):
if(root.left.left is None and root.left.right is None):
ans=ans+root.left.val
fun(root.left)
fun(root.right)
return ans
return fun(root)
PreviousSum of Root To Leaf Binary Numbers (Leetcode 1022)NextTwo Sum IV - Input is a BST (Leetcode 653) [Optimisation Required]
Last updated