-
Notifications
You must be signed in to change notification settings - Fork 40
/
4 August "Problem of the Day" Answer
47 lines (40 loc) · 1.21 KB
/
4 August "Problem of the Day" Answer
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
GeeksforGeeks
The Question is :- "Complete Binary Tree" :-
Answer :-
class Solution{
public:
bool isCompleteBT(Node* root){
//code here
queue<Node*>q1;
input code;
output_'
string;;
q1.push(root);
int flag=0;
while(!q1.empty()){
queue<Node*>q2;
while(!q1.empty()){
Node * temp=q1.front();
q1.pop();
if(flag==1){
if(temp->left!=NULL || temp->right!=NULL)return false;
}
if(temp->left!=NULL){
q2.push(temp->left);
}
if(temp->right!=NULL){
q2.push(temp->right);
}
if(temp->left==NULL && temp->right!=NULL)return false;
if(temp->left==NULL || temp->right==NULL){
flag=1;
}
}
q1=q2;
}
return true;
}
};
Hope you understand the answer, and complete it.
Stay Connected for daily Problem of the Day answers.
Thank you All!