cousins专题

Cousins in binary tree

Input: root = [1,2,3,null,4,null,5], x = 5, y = 4Output: true Input: root = [1,2,3,4], x = 4, y = 3Output: false 思路:就是level order traverse,BFS,记录一下parent, curNode, Depth; /*** Definition for

Blood Cousins CodeForces - 208E

http://codeforces.com/problemset/problem/208/E 问一个节点v有多少p兄弟 就等于看v的p祖先有多少p孩子 找p祖先就倍增或者树剖一下 然后就是某一层的节点中属于某棵子树的点有多少 用dfs序一判即可   #include <bits/stdc++.h>using namespace std;#define pb push_backcons

LeetCode每日一题——993. Cousins in Binary Tree

文章目录 一、题目二、题解 一、题目 Given the root of a binary tree with unique values and the values of two different nodes of the tree x and y, return true if the nodes corresponding to the values x and y

Leetcode之Cousins in Binary Tree

题目: 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.