1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/判断根结点是否等于子结点之和 [root-equals-sum-of-children].html
2022-04-24 17:05:32 +08:00

33 lines
1.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个 <strong>二叉树 </strong>的根结点&nbsp;<code>root</code>,该二叉树由恰好&nbsp;<code>3</code>&nbsp;个结点组成:根结点、左子结点和右子结点。</p>
<p>如果根结点值等于两个子结点值之和,返回&nbsp;<code>true</code>&nbsp;,否则返回<em>&nbsp;</em><code>false</code></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2022/04/08/graph3drawio.png" style="width: 281px; height: 199px;" />
<pre>
<strong>输入:</strong>root = [10,4,6]
<strong>输出:</strong>true
<strong>解释:</strong>根结点、左子结点和右子结点的值分别是 10 、4 和 6 。
由于 10 等于 4 + 6 ,因此返回 true 。
</pre>
<p><strong>示例 2</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2022/04/08/graph3drawio-1.png" style="width: 281px; height: 199px;" />
<pre>
<strong>输入:</strong>root = [5,3,1]
<strong>输出:</strong>false
<strong>解释:</strong>根结点、左子结点和右子结点的值分别是 5 、3 和 1 。
由于 5 不等于 3 + 1 ,因此返回 false 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li>树只包含根结点、左子结点和右子结点</li>
<li><code>-100 &lt;= Node.val &lt;= 100</code></li>
</ul>