/**
 * struct TreeNode {
 *  int val;
 *  struct TreeNode *left;
 *  struct TreeNode *right;
 *  TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 * };
 */
class Solution {
  public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     *
     * @param root TreeNode类
     * @return int整型
     */
    int findMaxHeight(TreeNode* root) {
        // write code here
        if (!root)return 0;
        int ans = root->val;
        if (root->left) ans = max(ans, findMaxHeight(root->left));
        if (root->right) ans = max(ans, findMaxHeight(root->right));
        return ans;
    }
};

一、题目考察的知识点

二叉树遍历

二、题目解答方法的文字分析

直接定义一个值去接收二叉树的值,然后递归调用遍历整个二叉树,与之前不同的是,之前都是求二叉树的最大高度,现在是求最大高度上的最大值,直接每次调用的时候用一个max函数就行

三、本题解析所用的编程语言

c++