public int dfs2(TreeNode root){
        if(root == null) return 0;

        int left = dfs2(root.left);
        if(left < 0) left = 0;

        int right = dfs2(root.right);
        if(right < 0) right = 0;

        int total = left + right + root.val;
        if(total > max) max = total;

        return root.val + Math.max(left, right);
    }