Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
21 lines (17 loc) · 583 Bytes

File metadata and controls

21 lines (17 loc) · 583 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package ch14;
import datatype.TreeNode;
public class P57_1 {
public int rangeSumBST(TreeNode root, int low, int high) {
// 예외 처리
if (root == null) return 0;
// 결과 변수
int result = 0;
// 현재 노드의 값이 low와 high 사이에 있다면 결과에 추가
if (low <= root.val && root.val <= high)
result = root.val;
// 자식 노드 재귀 DFS 진행
result += rangeSumBST(root.left, low, high);
result += rangeSumBST(root.right, low, high);
return result;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.