Skip to content

Commit 8fc7384

Browse files
committed
update
1 parent 7015aa4 commit 8fc7384

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

437_path_sum_iii.scala

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object Solution {
2+
def pathSum(root: TreeNode, sum: Int, cur_sum: Int = 0, initial: Boolean = true): Int = {
3+
if (root == null) 0
4+
else (if (sum == cur_sum + root.value) 1 else 0) + pathSum(root.left, sum, cur_sum + root.value, false) + pathSum(root.right, sum, cur_sum + root.value, false) + (if (initial) (pathSum(root.left, sum, 0, true) + pathSum(root.right, sum, 0, true)) else 0)
5+
}
6+
}

0 commit comments

Comments
 (0)