leetcode993】的更多相关文章

In a binary tree, the root node is at depth 0, and children of each depth knode are at depth k+1. Two nodes of a binary tree are cousins if they have the same depth, but have different parents. We are given the root of a binary tree with unique value…
In a binary tree, the root node is at depth 0, and children of each depth k node are at depth k+1. Two nodes of a binary tree are cousins if they have the same depth, but have different parents. We are given the root of a binary tree with unique valu…
public class Node { public int CurNode; public int FatherNode; public int Layer; } public class Solution { public List<Node> L = new List<Node>(); ) { if (root != null) { if (!L.Any()) { L.Add(, Layer = layer }); } if (root.left != null) { L.A…
题目 1 class Solution { 2 public: 3 TreeNode* r1;TreeNode* r2; 4 bool isCousins(TreeNode* root, int x, int y) { 5 dfs(root,r1,x); 6 dfs(root,r2,y); 7 int h_x = Depth(root,x); 8 int h_y = Depth(root,y); 9 if(h_x == h_y && r1 != r2) return true; 10 re…