← 返回 apple 的题目列表Count Occurrences of a Value in a Binary Tree
类型:online_judge
Given a binary tree and a target value, count the occurrences of the target value in the tree.
Input
An integer representing the root of the binary tree.
An integer representing the target value.
Output
An integer representing the number of times the target value appears in the binary tree.
Example
Input:
Binary tree = [5,4,8,11,null,13,4,7,2,null,null,5,1], target value = 4
Output:
3
Constraints
Number of nodes in the tree is [1, 1000].
Node values are within the range [-1000, 1000].
Example
Input
[5,4,8,11,null,13,4,7,2,null,null,5,1]
4