设计一个函数int countHeight(BinTreeNode *root),计算并返回一棵以root为根的二叉树的高度,(只有一个结点的二叉树高度为0),其中二叉树结点结构定义为:
typedef struct binTreeNode { int data; struct binTreeNode *left; struct binTreeNode *right; }BinTreeNode
int countHeight(BinTreeNode *root) { if (root == NULL) return 0; return max(countHeight(root.left), countHeight(root.right)) + 1; }
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题