Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1.  
  2. class Solution
  3. {
  4. public class Tree
  5. {
  6. public int x;
  7. public Tree l;
  8. public Tree r;
  9. }
  10.  
  11. public int solution(Tree t)
  12. {
  13. HashSet<int> numbers = new HashSet<int>();
  14.  
  15. return ParseTree(t, numbers);
  16. }
  17.  
  18. public int ParseTree(Tree t, HashSet<int> numbers)
  19. {
  20. if (t == null) return numbers.Count;
  21.  
  22. numbers.Add(t.x);
  23.  
  24. return System.Math.Max(ParseTree(t.r, new HashSet<int>(numbers)), ParseTree(t.l, new HashSet<int>(numbers)));
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement