Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution
- {
- public class Tree
- {
- public int x;
- public Tree l;
- public Tree r;
- }
- public int solution(Tree t)
- {
- HashSet<int> numbers = new HashSet<int>();
- return ParseTree(t, numbers);
- }
- public int ParseTree(Tree t, HashSet<int> numbers)
- {
- if (t == null) return numbers.Count;
- numbers.Add(t.x);
- return System.Math.Max(ParseTree(t.r, new HashSet<int>(numbers)), ParseTree(t.l, new HashSet<int>(numbers)));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement