We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No description provided.
The text was updated successfully, but these errors were encountered:
/** * @param {TreeNode} root * @return {boolean} */ var isCompleteTree = function(root) { const queue = [root]; let leaf = false; //标记是否已经遇到过左右叶子不完整的节点 while(queue.length){ let len = queue.length; let node = queue.shift(); if(!node.left && node.right){ //有右节点没左节点,肯定不是完全二叉树 return false; } if(leaf && (node.left || node.right)){ // 如果已经遇到过左右节点不完整的节点了,还碰到不是叶子节点的节点,也不是完全二叉树 return false; } node.left && queue.push(node.left); node.right && queue.push(node.right); if(!leaf && (!node.left || !node.right)){ //首次碰到左右不全的节点,leaf为true; leaf = true; } } return true; };
Sorry, something went wrong.
No branches or pull requests
No description provided.
The text was updated successfully, but these errors were encountered: