-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem8.java
More file actions
52 lines (46 loc) · 1.27 KB
/
Copy pathProblem8.java
File metadata and controls
52 lines (46 loc) · 1.27 KB
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package dailycodingchallange;
public class DAY8 {
public static void main(String[] args) {
Universal univ=new Universal();
univ.isUniv(root);//root is the root of the given tree.
}
}
class Universal
{
int leaf=0,k=0;
Universal root=null;
int val;
Universal left,right;
Universal(int va)
{
val=va;
left=right=null;
}
Universal()
{
}
void isUniv(Universal root)
{
int noOfUniv=FindUniversal(root,root.val);
System.out.println("NoOf Universal tree in the given tree is:"+noOfUniv);
}
int FindUniversal(Universal root,int val)
{
if(root==null)
return 0;
boolean isUniv=true;
if(left!=null&&left.val!=val)
isUniv=false;
if(right!=null&&right.val!=val)
isUniv=false;
if(isUniv==true)
return(FindUniversal(root.left,left.val)+FindUniversal(root.right,right.val)+1);
else
return(FindUniversal(root.left,left.val)+FindUniversal(root.right,right.val));
}
}