1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-22 13:36:46 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2022-03-29 16:56:27 +08:00
parent e730aa6794
commit ad15da05aa
2517 changed files with 7358 additions and 7332 deletions

View File

@@ -12,7 +12,7 @@
"translatedContent": "<p>给你一个二叉树的根节点 <code>root</code> ,计算并返回 <strong>整个树 </strong>的坡度 。</p>\n\n<p>一个树的<strong> 节点的坡度 </strong>定义即为,该节点左子树的节点之和和右子树节点之和的 <strong>差的绝对值 </strong>。如果没有左子树的话,左子树的节点之和为 0 ;没有右子树的话也是一样。空结点的坡度是 0 。</p>\n\n<p><strong>整个树</strong> 的坡度就是其所有节点的坡度之和。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2020/10/20/tilt1.jpg\" style=\"width: 712px; height: 182px;\" />\n<pre>\n<strong>输入:</strong>root = [1,2,3]\n<strong>输出:</strong>1\n<strong>解释:</strong>\n节点 2 的坡度:|0-0| = 0没有子节点\n节点 3 的坡度:|0-0| = 0没有子节点\n节点 1 的坡度:|2-3| = 1左子树就是左子节点所以和是 2 ;右子树就是右子节点,所以和是 3 \n坡度总和0 + 0 + 1 = 1\n</pre>\n\n<p><strong>示例 2</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2020/10/20/tilt2.jpg\" style=\"width: 800px; height: 203px;\" />\n<pre>\n<strong>输入:</strong>root = [4,2,9,3,5,null,7]\n<strong>输出:</strong>15\n<strong>解释:</strong>\n节点 3 的坡度:|0-0| = 0没有子节点\n节点 5 的坡度:|0-0| = 0没有子节点\n节点 7 的坡度:|0-0| = 0没有子节点\n节点 2 的坡度:|3-5| = 2左子树就是左子节点所以和是 3 ;右子树就是右子节点,所以和是 5 \n节点 9 的坡度:|0-7| = 7没有左子树所以和是 0 ;右子树正好是右子节点,所以和是 7 \n节点 4 的坡度:|(3+5+2)-(9+7)| = |10-16| = 6左子树值为 3、5 和 2 ,和是 10 ;右子树值为 9 和 7 ,和是 16 \n坡度总和0 + 0 + 0 + 2 + 7 + 6 = 15\n</pre>\n\n<p><strong>示例 3</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2020/10/20/tilt3.jpg\" style=\"width: 800px; height: 293px;\" />\n<pre>\n<strong>输入:</strong>root = [21,7,14,1,1,2,2,3,3]\n<strong>输出:</strong>9\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li>树中节点数目的范围在 <code>[0, 10<sup>4</sup>]</code> 内</li>\n\t<li><code>-1000 &lt;= Node.val &lt;= 1000</code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Easy",
"likes": 252,
"likes": 253,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -149,7 +149,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"63.3K\", \"totalSubmission\": \"96.6K\", \"totalAcceptedRaw\": 63303, \"totalSubmissionRaw\": 96621, \"acRate\": \"65.5%\"}",
"stats": "{\"totalAccepted\": \"63.4K\", \"totalSubmission\": \"96.8K\", \"totalAcceptedRaw\": 63389, \"totalSubmissionRaw\": 96750, \"acRate\": \"65.5%\"}",
"hints": [
"Don't think too much, this is an easy problem. Take some small tree as an example.",
"Can a parent node use the values of its child nodes? How will you implement it?",