求解求解
特殊二叉树具有以下性质:
1. Each node in the tree has exactly 2 children except thleaf nodes .
2. Each node is painted with white color or black color
3. The color of the root node is black.
4. for each non.leaf node, the color of its left child isdifferent from the color of its right child.
已知树的叶子节点数是N,给定一个数组arr,大小为N,arr[i] means the number of white color nodes in the path from the root node to the i-th leaf node in the DFS order. The Dfs order in here means preorder traversal. The rootnode ofthe subtre is visited frst Then the left subtree istraversed. At last,the right subtree is traversed
给定叶子节点数以及数组arr,判断是否有特殊二叉树满足数组arr的条件,如果满足就打印YES,否则打印NO。
示例1
输入:
5
0 1 2 1 2
输出
YES
示例2
输入:
5
0 3 1 2 1
输出
NO
1. Each node in the tree has exactly 2 children except thleaf nodes .
2. Each node is painted with white color or black color
3. The color of the root node is black.
4. for each non.leaf node, the color of its left child isdifferent from the color of its right child.
已知树的叶子节点数是N,给定一个数组arr,大小为N,arr[i] means the number of white color nodes in the path from the root node to the i-th leaf node in the DFS order. The Dfs order in here means preorder traversal. The rootnode ofthe subtre is visited frst Then the left subtree istraversed. At last,the right subtree is traversed
给定叶子节点数以及数组arr,判断是否有特殊二叉树满足数组arr的条件,如果满足就打印YES,否则打印NO。
示例1
输入:
5
0 1 2 1 2
输出
YES
示例2
输入:
5
0 3 1 2 1
输出
NO
全部评论
相关推荐
双非25想找富婆不想打工:哦,这该死的伦敦腔,我敢打赌,你简直是个天才,如果我有offer的话,我一定用offer狠狠的打在你的脸上
点赞 评论 收藏
分享