题目描述
Given a binary tree and a budget. Assume you are at the root of the tree(level 1), you need to maximise the count of leaf nodes you can visit in your budget if the cost of visiting a leaf node is equal to the level of that leaf node.
Example 1:
Input:
10
/ \
8 2
/ / \
3 3 6
\
4
and budget = 8
Output: 2
Explanation:
Cost For visiting Leaf Node 3: 3
Cost For visiting Leaf Node 4: 4
Cost For visiting Leaf Node 6: 3
In budget 8 one can visit Max 2 Leaf Nodes.
Example 2:
Input:
1
/ \
2 3
/ \ / \
4 5 6 7
and budget = 5
Output: 1
Your Task:
You don't need to read input or print anything. Your task is to complete the function getCount() which takes root node of the tree and a integer denoting the budget as input parameters and returns an integer denoting the count of visited leaf nodes of the tree.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=T<=10^{3}
1<=N<=10^{4}
1<=budget<=10^{4}
输入格式
见题面
输出格式
见题面