Java DFS AC Solution


  • 0
    T

    Can anyone tell me how to format the code? I use ''' my code ''' to include the code, but it still shows like below.

    '''
    public class Solution {
    int res = 0;
    public int sumOfLeftLeaves(TreeNode root) {
    helper(root, false);
    return res;
    }
    private void helper(TreeNode root, boolean isleft){
    if(root == null)
    return;
    if (root.left == null && root.right == null && isleft)
    res += root.val;
    helper(root.left, true);
    helper(root.right, false);
    }
    }
    '''


Log in to reply
 

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