private void count(Node x, int[] result) {
    if (x == null) {
      return;
    }
    boolean hasNoChildren = true;
    for (char c = 0; c < K; c++) {
      if (x.children[c] != null) {
        hasNoChildren = false;
        count(x.children[c], result);
      }
    }
    if (hasNoChildren) {
      result[0]++;
    }
  }