求解求解

特殊二叉树具有以下性质:
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
全部评论

相关推荐

04-01 17:59
已编辑
西南交通大学 C++
牛客81125572...:放心吧,我第一次面字节,三面都是easy题加纯八股,横向了几天挂了。第二次面也是纯八股➕聊天,hot100的mid和hard,一直秒过,说是easy也不为过。现在已经入职了题简单说明面试官不想卡你
发面经攒人品
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务