Skip to content

Commit 83a2a6a

Browse files
committed
update
1 parent b2fc2bf commit 83a2a6a

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Scala/Tree/LeetCode0113.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
package com.leetcode.tree
21

32
class TreeNode(var _value: Int) {
43
var value: Int = _value
@@ -8,18 +7,18 @@ class TreeNode(var _value: Int) {
87

98
object LeetCode0113 {
109
def pathSum(root: TreeNode, sum: Int): List[List[Int]] = {
11-
if (root == null || sum == 0) {
1210

13-
}
1411
if (root == null) return List();
12+
if (root != null && root.left == null && root.right == null && sum == root.value) {
13+
return List(List(sum));
14+
}
1515
var path: List[List[Int]] = List();
16-
if (root.left != null && sum > root.value) {
16+
if (root.left != null && sum != root.value) {
1717
path :::= pathSum(root.left, sum - root.value).map(root.value :: _);
1818
}
19-
if (root.right != null && sum > root.value) {
19+
if (root.right != null && sum != root.value) {
2020
path :::= pathSum(root.right, sum - root.value).map(root.value :: _);
2121
}
2222
path;
2323
}
2424
}
25-

0 commit comments

Comments
 (0)