classSolution { public: intdepth(TreeNode *root, int &ret){ if(!root) return0; int l = depth(root->left, ret); int r = depth(root->right, ret); ret = max(r+l, ret); return1+max(l, r); } intdiameterOfBinaryTree(TreeNode* root){ if(!root) return0; int ret = 0; depth(root, ret); return ret; } };