Given a node of the general tree, find the number of children of that node

Ideas

Given a node in the tree, find its first child node, and then traverse all the sibling nodes of the child node to find the solution

Code

int childCount(TreeNode current){
    
    
  int count = 0;
  current = current.getFirstChild();
  while(current != null){
    
    
    count++;
    current = current.getNextSibling();
  }
  return count;
}

Guess you like

Origin blog.csdn.net/weixin_37632716/article/details/115143119