Number of Good Leaf Nodes Pairs (Leetcode 1530)

preview_player
Показать описание

Leetcode 1530. Number of Good Leaf Nodes Pairs:

Problem:
Calculate the number of good leaf pairs in a tree, such that a pair of leaf nodes are good if the length of the shortest path between them is ≤ `distance`

Example 1:
1
3 6
5

tree: [1,3,5,null,6], distance = 3
result = 1

Example 2
1
2 5
3 4 8 9

root = [1,2,5,3,4,8,9], distance = 3
good pairs are [3,4] and [8,9]

result: 2
Рекомендации по теме