“`”
参考回答:
<pre><code>public int maxTreeNode(TreeNode root) {
if (root.left == null && root.right == null) {
return root.val;
} else {
if (root.left != null && root.right != null) {
return root.val > maxTreeNode(root.left) ? (root.val > maxTreeNode(root.right) ? root.val
: maxTreeNode(root.right))
: (maxTreeNode(root.left) > maxTreeNode(root.right) ? maxTreeNode(root.left)
: maxTreeNode(root.right));
} else if (root.left == null && root.right != null) {
return root.val > maxTreeNode(root.right) ? root.val
: maxTreeNode(root.right);
} else {
return root.val > maxTreeNode(root.left) ? root.val
: maxTreeNode(root.left);
}
}
}
</code></pre>
<pre><code> "“`
Was this helpful?
0 /
0