Given a node of the universal tree, find the number of sibling nodes java

Ideas

For a given node in the tree, just traverse the count of all its sibling nodes

Code

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

Guess you like

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