SHARE
TWEET

Untitled

a guest May 19th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top