-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathCoronaVaccine.java
42 lines (33 loc) · 893 Bytes
/
CoronaVaccine.java
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class Solution{
static int ans = 0;
static int post(Node node) {
boolean zero = false, two = false;
if(node.left == null && node.right == null) return 0;
if(node.left != null) {
int get = post(node.left);
if(get == 0) zero = true;
if(get == 2) two = true;
}
if(node.right != null) {
int get = post(node.right);
if(get == 0) zero = true;
if(get == 2) two = true;
}
if(zero) {
ans++;
return 2;
}
if(two) {
return 1;
}
return 0;
}
public static int supplyVaccine(Node root){
ans = 0;
int result = post(root);
if(result == 0) {
return ans+1;
}
return ans;
}
}