public static int[] FindFrequentTreeSum(LeetCode508TreeNode root)
        {
            if (root == null)
            {
                return(new int[0]);
            }
            var maxSumValue = map.Max(msv => msv.Value);
            var ans         = new List <int>();

            foreach (var item in map)
            {
                if (maxSumValue == item.Value)
                {
                    ans.Add(item.Key);
                }
            }

            return(ans.ToArray());
        }
        private static int Helper(LeetCode508TreeNode root)
        {
            if (root == null)
            {
                return(0);
            }

            var left  = Helper(root.left);
            var right = Helper(root.right);

            var sum = 0;

            sum = root.val + left + right;

            // this condition means we found the duplicate summary num
            if (!map.TryAdd(sum, 1))
            {
                // Frequent + 1
                map[sum]++;
            }

            return(sum);
        }
 public LeetCode508TreeNode(int val = 0, LeetCode508TreeNode left = null, LeetCode508TreeNode right = null)
 {
     this.val   = val;
     this.left  = left;
     this.right = right;
 }