# 0958. Check Completeness of a Binary Tree ###### tags: `Leetcode` `FaceBook` `Medium` `BFS` Link: https://leetcode.com/problems/check-completeness-of-a-binary-tree/ ## 思路 解法很简单,如果pop出来的元素是null,但是queue的peek不是null,那么就要return false ## Code ```java= class Solution { public boolean isCompleteTree(TreeNode root) { Queue<TreeNode> q = new LinkedList<>(); q.add(root); int nodeNum = 1; while(!q.isEmpty()){ TreeNode node = q.poll(); if(node!=null){ q.add(node.left); q.add(node.right); } else{ if(!q.isEmpty() && q.peek()!=null){ return false; } } } return true; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up