-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathPartitionTree.java
61 lines (55 loc) · 1.25 KB
/
PartitionTree.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*https://binarysearch.com/problems/Partition-Tree*/
class Solution {
int[] res;
public int[] solve(Tree root) {
res = new int[2];
recur(root);
return res;
}
public void recur(Tree root)
{
if (root == null) return;
recur(root.left);
if (root.left == null && root.right == null) ++res[0];
else ++res[1];
recur(root.right);
}
}
/*
class Solution {
ArrayList<Integer> al;
public int[] solve(Tree root) {
al=new ArrayList<>();
inorder(root);
int ans[]=new int[al.size()];
for(int i=0;i<ans.length;i++)
{
ans[i]=al.get(i);
}
return ans;
}
public void inorder(Tree root)
{
if(root==null)
return;
Stack<Tree> stack=new Stack<>();
Tree current=root;
while(current!=null)
{
stack.push(current);
current=current.left;
}
while(!stack.isEmpty())
{
current=stack.pop();
al.add(current.val);
current=current.right;
while(current!=null)
{
stack.push(current);
current=current.left;
}
}
}
}
*/