-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfull-tree.js
More file actions
34 lines (27 loc) · 705 Bytes
/
full-tree.js
File metadata and controls
34 lines (27 loc) · 705 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
28
29
30
31
32
33
34
// the full bainary tree;
// the parent of full bainary tree must have two child or nothing ;
class TreeNode {
constructor(data) {
this.data =data;
this.right = null;
this.left = null;
}
}
function isFullBainaryTree(node) {
if(node == null) {
return true;
}
if(node.left == null && node.right == null) {
return true
}
if(!!node.left && !!node.right) {
return isFullBainaryTree(node.left) && isFullBainaryTree(node.right);
}
return false
}
const headNode = new TreeNode(1);
headNode.left = new TreeNode(2);
headNode.right = new TreeNode(3);
headNode.left.left = new TreeNode(4);
headNode.left.right= new TreeNode(5);
console.log(isFullBainaryTree(headNode))