Given the root of a binary tree, determine whether it is perfect — all internal nodes have two children and all leaves are at the same depth. Return true or false. The tree is given as a level-order array with null for missing children.
Input: A level-order array of the tree.
Output: Boolean — true or false.
Input: [1,2,3,4,5,6,7]
Output: true
Explanation: All leaves at the same depth, internal nodes have two children.Input: [1,2,3,4,5,6]
Output: false
Explanation: Last level is not full.Input: [1]
Output: true
Explanation: Single node.0<=nodes<=10^4-1000<=value<=1000