剑指offer-面试题39 : 二叉树的深度

    xiaoxiao2021-03-25  117

    #include<windows.h> typedef struct TreeNode* Node; struct TreeNode { int nValue; Node pLeft; Node pRight; }; int BinaryTreeDepth(Node TreeRoot) { if(TreeRoot == NULL) return 0; int nLeftDepth = BinaryTreeDepth(TreeRoot->pLeft); int nRightDepth = BinaryTreeDepth(TreeRoot->pRight); return (nLeftDepth > nRightDepth) ? nLeftDepth+1 : nRightDepth+1; }
    转载请注明原文地址: https://ju.6miu.com/read-21037.html

    最新回复(0)