/* 题目: 二叉树的深度 */ /* 思路: 根节点高度(0或1)+左子树的深度+右子树的深度 */ #include<iostream> #include<cstring> #include<vector> #include<algorithm> #include<map> using namespace std; struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { } }; int verse(TreeNode* pRoot){ if(pRoot == nullptr){ return 0; } int leftDepth = verse(pRoot->left); int rightDepth = verse(pRoot->right); return max(leftDepth,rightDepth) +1; } int TreeDepth(TreeNode* pRoot) { return verse(pRoot); }