求解求解

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

相关推荐

06-23 17:45
门头沟学院 Java
里面的项目啥的真的有用吗? 这些人是割韭菜吗?
HellowordX:很简单,如果你有自己稳定的学习路线和获取知识的方式就没必要,如果你啥都不懂的小白或者里边有你感兴趣的知识,我觉得挺值,我也经常为知识付费,因为时间精力有限,很多东西我不可能自己重复造轮子
点赞 评论 收藏
分享
认真搞学习:28小登的建议,投算法岗不要写什么物理竞赛,互联网+,多写点项目,用什么算法做了什么。还有本科算法是不可能的开发你这个也没有项目啊
点赞 评论 收藏
分享
05-29 20:34
门头沟学院 C++
KarlAllen:得做好直接春招的准备。学历差的话,一是面试要求会比学历好的严格不少,二是就算面试通过了也会被排序。总之暑期和秋招对于学历差的就是及其不友好
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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