Advertisement
Guest User

Untitled

a guest
May 19th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.39 KB | None | 0 0
  1. class Solution
  2. {
  3.     public int solution(Tree node)
  4.     {
  5.         return countVisible(node, 0) + 1;
  6.     }
  7.    
  8.     private int countVisible(Tree node, int current_max)
  9.     {
  10.         if (node == null)
  11.             return 0;
  12.        
  13.         int count_me = current_max < node.x ? 1 : 0;
  14.         current_max = Math.Max(current_max, node.x);
  15.        
  16.         return countVisible(node.r, current_max)
  17.             + countVisible(node.l, current_max)
  18.             + count_me;
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement