functionisCompleteTree(root){
if(!root)returntrue;var flag =0;var queue =[];
queue.push(root);while(queue.length !=0){
var node = queue.shift();if(!node.left)
flag =1;//表示后面不能有节点了elseif(node.left && flag ==0)
queue.push(node.left);elseif(node.left && flag ==1)returnfalse;if(!node.right)
flag =1;elseif(node.right && flag ==0)
que.push(node.right);elseif(node.right && flag ==1)returnfalse;}returntrue;}
判断是否为平衡二叉树
functionmaxDepthOfTree(node){
if(!node)return0;return Math.max(maxDepthOfTree(node.left),maxDepthOfTree(node.right))+1;}functionisBalanced(node){
if(!node)returntrue;var left =maxDepthOfTree(node.left);var right =maxDepthOfTree(node.right);if(Math.abs(left-right)>1)returnfalse;returnisBalanced(node.left)&&isBalanced(node.right);}