求解求解
特殊二叉树具有以下性质:
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
全部评论
相关推荐
10-21 18:18
中南大学 机械设计/制造 点赞 评论 收藏
分享
沉淀一会:1.同学你面试评价不错,概率很大,请耐心等待;
2.你的排名比较靠前,不要担心,耐心等待;
3.问题不大,正在审批,不要着急签其他公司,等等我们!
4.预计9月中下旬,安心过节;
5.下周会有结果,请耐心等待下;
6.可能国庆节前后,一有结果我马上通知你;
7.预计10月中旬,再坚持一下;
8.正在走流程,就这两天了;
9.同学,结果我也不知道,你如果查到了也告诉我一声;
10.同学你出线不明朗,建议签其他公司保底!
11.同学你找了哪些公司,我也在找工作。
点赞 评论 收藏
分享