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…