SHARE
TWEET

Untitled

a guest May 19th, 2019 52 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.         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. }
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