File tree Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change 1
- package com .leetcode .tree
2
1
3
2
class TreeNode (var _value : Int ) {
4
3
var value : Int = _value
@@ -8,18 +7,18 @@ class TreeNode(var _value: Int) {
8
7
9
8
object LeetCode0113 {
10
9
def pathSum (root : TreeNode , sum : Int ): List [List [Int ]] = {
11
- if (root == null || sum == 0 ) {
12
10
13
- }
14
11
if (root == null ) return List ();
12
+ if (root != null && root.left == null && root.right == null && sum == root.value) {
13
+ return List (List (sum));
14
+ }
15
15
var path : List [List [Int ]] = List ();
16
- if (root.left != null && sum > root.value) {
16
+ if (root.left != null && sum != root.value) {
17
17
path :::= pathSum(root.left, sum - root.value).map(root.value :: _);
18
18
}
19
- if (root.right != null && sum > root.value) {
19
+ if (root.right != null && sum != root.value) {
20
20
path :::= pathSum(root.right, sum - root.value).map(root.value :: _);
21
21
}
22
22
path;
23
23
}
24
24
}
25
-
You can’t perform that action at this time.
0 commit comments