<?php
class TreeNode{
var $val;
var $left = NULL;
var $right = NULL;
function __construct($val){
$this->val = $val;
}
}
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param root TreeNode类
* @return bool布尔型
*/
function isCompleteTree( $root )
{
if($root->left == NULL && $root->right == NULL){
return true;
}
$queue = array($root);
while(($node = array_pop($queue)) != NULL){
//数组最前面插入
array_unshift($queue,$node->left);
array_unshift($queue,$node->right);
}
while(count($queue)){
$node = array_pop($queue);
if($node != null){
return false;
}
}
return true;
}