-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLC938.java
More file actions
27 lines (23 loc) · 795 Bytes
/
LC938.java
File metadata and controls
27 lines (23 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Diego Estrada Talamantes
// devdiegoest@gmail.com
public class LC938{
public static void main(String[] args) {
long startTime = System.nanoTime();
// Aquí escribimos el método respuesta
System.out.println();
long endTime = System.nanoTime();
long totalTime = (endTime - startTime) / 1000000;
System.out.println("Tiempo: "+totalTime+" ms");
}
public int rangeSumBST(TreeNode root, int L, int R) {
int suma = 0;
suma = (root.val>=L && root.val<=R ? suma+root.val : suma);
if(root.left!=null){
suma += rangeSumBST(root.left, L, R);
}
if(root.right!=null){
suma += rangeSumBST(root.right, L, R);
}
return suma;
}
}