Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution
- {
- public int solution(Tree node)
- {
- return countVisible(node, 0) + 1;
- }
- private int countVisible(Tree node, int current_max)
- {
- if (node == null)
- return 0;
- int count_me = current_max < node.x ? 1 : 0;
- current_max = Math.Max(current_max, node.x);
- return countVisible(node.r, current_max)
- + countVisible(node.l, current_max)
- + count_me;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement