判断二叉搜索树是否为AVL树

int isAVL(BinarySearchTreeNode root){
  int left = 0;
  int right = 0;
  if(root == null){
    return 0;
  }
  left = isAVL(root.getLeft());
  if(left == -1){
    return left;
  }
  right = isAVL(root.getRight());
  if(right == -1){
    return right;
  }
  if(Math.abs(left - right) > 1){
    return -1;
  }
  return Math.max(left,right)+1
}

你可能感兴趣的:(数据结构与算法,算法,java)