Skip to content

Commit 5ea5695

Browse files
update 938
1 parent b95c4e1 commit 5ea5695

File tree

1 file changed

+8
-4
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+8
-4
lines changed

Diff for: src/main/java/com/fishercoder/solutions/_938.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@ public int rangeSumBST(TreeNode root, int low, int high) {
1616
return list.stream().mapToInt(num -> num).sum();
1717
}
1818

19-
private void dfs(TreeNode root, int l, int r, List<Integer> list) {
19+
private void dfs(TreeNode root, int low, int high, List<Integer> list) {
2020
if (root == null) {
2121
return;
2222
}
23-
if (root.val <= r && root.val >= l) {
23+
if (root.val <= high && root.val >= low) {
2424
list.add(root.val);
2525
}
26-
dfs(root.left, l, r, list);
27-
dfs(root.right, l, r, list);
26+
if (root.val > low) {
27+
dfs(root.left, low, high, list);
28+
}
29+
if (root.val < high) {
30+
dfs(root.right, low, high, list);
31+
}
2832
}
2933
}
3034
}

0 commit comments

Comments
 (0)