In a binary tree, the root node is at depth0, and children of each depthknode are at depthk+1. Two nodes of a binary tree arecousinsif they have the same depth, but have different parents. We are given therootof a binary tree with unique values, and the valuesxandyof two different...
The cousin nodes of the BIT refer to the two nodes which locate in the same level and whose parents are different. Ideology of Algorithm 显然,我们可以用广度优先方法遍历整棵二叉树。我们需要建立两个逻辑值x_visited和y_visited去标记x、y是否已被找到。当遍历到当前结点时,我们检查左右孩子值是否为x...