Advertisement
Guest User

Untitled

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