标签:思路 math root boolean lang return scom pre 简介
思路: 个数和序号相等
class Solution {
int size = 0;
int maxCode = 0;
public boolean isCompleteTree(TreeNode root) {
if(root == null) return true;
recursive(root, 1);
return size == maxCode;
}
public void recursive(TreeNode root, int index) {
if(root == null) return;
size ++;
maxCode = Math.max(maxCode, index);
recursive(root.left, index * 2);
recursive(root.right, index * 2 + 1);
}
}
标签:思路 math root boolean lang return scom pre 简介
原文地址:https://www.cnblogs.com/eat-too-much/p/14867473.html