LeetCode: Maximum XOR of Two Numbers in an Array
In XorTreeNode you're not using the field Val




public void Insert(int[] nums)
public int GetMax(int[] nums)



Having two methods that must take the same data to operate on is hazardous and should be avoided. Either provide the data to the constructor or you should only have one public method with the data set as argument:

public int FindMaxXor(int[] nums) { Insert(nums); return GetMax(nums) }




You can invert a bit in the following way:

bit ^ 1


It can be used to simplify this:


                int bit = (num &gt;&gt; i) &amp; 1;
                if (cur.children[bit == 1 ? 0 : 1] != null)
                {
                    xorValue += (1 &lt;&lt; i);
                    cur = cur.children[bit == 1 ? 0 : 1];
                }
                else
                {
                    cur = cur.children[bit];
                }



to

        int bit = ((num &gt;&gt; i) &amp; 1) ^ 1;
        if (cur.children[bit] != null)
        {
          xorValue += (1 &lt;&lt; i);
          cur = cur.children[bit];
        }
        else
        {
          cur = cur.children[bit ^ 1];
        }




You can insert numbers and search for max in the same operation, because every new number only need to compare with already existing numbers.

So you can change GetMax(...) to:

private int GetMax(int num)
{
  XorTreeNode cur = _root;
  int xorValue = 0;
  for (int i = _numBits; cur != null &amp;&amp; i &gt;= 0; i--)
  {
    int bit = ((num &gt;&gt; i) &amp; 1) ^ 1;
    if (cur.children[bit] != null)
    {
      xorValue += (1 &lt;&lt; i);
      cur = cur.children[bit];
    }
    else
    {
      cur = cur.children[bit ^ 1];
    }
  }

  return xorValue;
}


and Insert(...) to:

public int FindMaxXor(int[] nums)
{
  int result = int.MinValue;

  foreach (var num in nums)
  {
    result = Math.Max(result, GetMax(num));

    XorTreeNode cur = _root;
    for (int i = _numBits; i &gt;= 0; i--)
    {
      int bit = (num &gt;&gt; i) &amp; 1;
      if (cur.children[bit] == null)
      {
        cur.children[bit] = new XorTreeNode();
      }
      cur = cur.children[bit];
    }
  }

  return result;
}


where _numBits is defined as a class const field:

private const int _numBits = 31;




If you know that the nums array contains only small values there might be a significant performance improvement in finding the leftmost significant bit:

  int max = nums.Max();
  while (max &gt; 0)
  {
    _numBits++;
    max &gt;&gt;= 1;
  }


in the start of the Insert(...) method. _numBits should then not be const and initialized to zero obviously. 
If the numbers span over the entire int+ domain this may slow the entire process.