Skip to content

Commit 5828e00

Browse files
authored
feat: update lc problems (#5162)
1 parent 0d48dc4 commit 5828e00

3 files changed

Lines changed: 32 additions & 30 deletions

File tree

solution/3900-3999/3902.Zigzag Level Sum of Binary Tree/README.md

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,78 +6,80 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3900-3999/3902.Zi
66

77
<!-- problem:start -->
88

9-
# [3902. Zigzag Level Sum of Binary Tree 🔒](https://leetcode.cn/problems/zigzag-level-sum-of-binary-tree)
9+
# [3902. 二叉树的 Z 字形层级和 🔒](https://leetcode.cn/problems/zigzag-level-sum-of-binary-tree)
1010

1111
[English Version](/solution/3900-3999/3902.Zigzag%20Level%20Sum%20of%20Binary%20Tree/README_EN.md)
1212

1313
## 题目描述
1414

1515
<!-- description:start -->
1616

17-
<p>You are given the <code>root</code> of a <strong>binary tree</strong>.</p>
17+
<p>给定一棵 <strong>二叉树</strong> 的根节点&nbsp;<code>root</code>。</p>
1818

19-
<p>Traverse the tree level by level using a zigzag pattern:</p>
19+
<p>按 Z 字形模式逐层遍历树:</p>
2020

2121
<ul>
22-
<li>At <strong>odd</strong>-numbered levels (1-indexed), traverse nodes from <strong>left to right</strong>.</li>
23-
<li>At <strong>even</strong>-numbered levels, traverse nodes from <strong>right to left</strong>.</li>
22+
<li> <strong>奇数</strong> 层(下标从 1 开始)中,<strong>从左到右</strong> 遍历节点。</li>
23+
<li> <strong>偶数</strong> 层,<strong>从右到左</strong> 遍历节点。</li>
2424
</ul>
2525

26-
<p>While traversing a level in the specified direction, process nodes in order and <strong>stop</strong> immediately before the first node that violates the condition:</p>
26+
<p>在指定方向遍历某一层时,按顺序处理节点,并立即在第一个违反条件的节点前 <strong>停止</strong></p>
2727

2828
<ul>
29-
<li>At <strong>odd</strong> levels: the node does not have a <strong>left</strong> child.</li>
30-
<li>At <strong>even</strong> levels: the node does not have a <strong>right</strong> child.</li>
29+
<li> <strong>奇数</strong> 层:该节点没有 <strong></strong> 子节点。</li>
30+
<li> <strong>偶数</strong> 层:该节点没有 <strong></strong> 子节点。</li>
3131
</ul>
3232

33-
<p>Only the nodes processed before this stopping condition contribute to the level sum.</p>
33+
<p>只有在此停止条件之前的节点对层级和有贡献。</p>
3434

35-
<p>Return an integer array <code>ans</code> where <code>ans[i]</code> is the <strong>sum</strong> of the node values that are processed at level <code>i + 1</code>.</p>
35+
<p>返回一个整数数组 <code>ans</code>,其中 <code>ans[i]</code> 是在第 <code>i + 1</code> 层处理的节点值之 <strong>和</strong>。</p>
3636

3737
<p>&nbsp;</p>
38-
<p><strong class="example">Example 1:</strong></p>
38+
39+
<p><b>示例 1:</b></p>
3940

4041
<div class="example-block">
41-
<p><strong>Input:</strong> <span class="example-io">root = [5,2,8,1,null,9,6]</span></p>
42+
<p><span class="example-io"><b>输入:</b>root = [5,2,8,1,null,9,6]</span></p>
4243

43-
<p><strong>Output:</strong> <span class="example-io">[5,8,0]</span></p>
44+
<p><span class="example-io"><b>输出:</b>[5,8,0]</span></p>
4445

45-
<p><strong>Explanation:</strong></p>
46+
<p><strong>解释:</strong></p>
4647

4748
<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3900-3999/3902.Zigzag%20Level%20Sum%20of%20Binary%20Tree/images/screenshot-2026-04-13-at-22054am.png" style="height: 240px; width: 300px;" />​​​​​​​</p>
4849

4950
<ul>
50-
<li>At level 1, nodes are processed left to right. Node 5 is included, thus <code>ans[0] = 5</code>.</li>
51-
<li>At level 2, nodes are processed right to left. Node 8 is included, but node 2 lacks a right child, so processing stops, thus <code>ans[1] = 8</code>.</li>
52-
<li>At level 3, nodes are processed left to right. The first node 1 lacks a left child, so no nodes are included, and <code>ans[2] = 0</code>.</li>
53-
<li>Thus, <code>ans = [5, 8, 0]</code>.</li>
51+
<li>在第 1 层,从左往右处理节点。节点 5 被包含,因此&nbsp;<code>ans[0] = 5</code></li>
52+
<li>在第 2&nbsp;层,从右往左处理节点。节点 8 被包含,但节点 2 缺少一个右儿子,所以处理中断,因此&nbsp;<code>ans[1] = 8</code></li>
53+
<li>在第 3&nbsp;层,从左往右处理节点。第一个节点 1 缺少一个左儿子,因此没有节点被包含,因此&nbsp;<code>ans[2] = 0</code></li>
54+
<li>因此,<code>ans = [5, 8, 0]</code></li>
5455
</ul>
5556
</div>
5657

57-
<p><strong class="example">Example 2:</strong></p>
58+
<p><strong class="example">示例 2:</strong></p>
5859

5960
<div class="example-block">
60-
<p><strong>Input:</strong> <span class="example-io">root = [1,2,3,4,5,null,7]</span></p>
61+
<p><span class="example-io"><b>输入:</b>root = [1,2,3,4,5,null,7]</span></p>
6162

62-
<p><strong>Output:</strong> <span class="example-io">[1,5,0]</span></p>
63+
<p><span class="example-io"><b>输出:</b>[1,5,0]</span></p>
6364

64-
<p><strong>Explanation:</strong></p>
65+
<p><b>解释:</b></p>
6566

6667
<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3900-3999/3902.Zigzag%20Level%20Sum%20of%20Binary%20Tree/images/screenshot-2026-04-13-at-22232am.png" style="height: 254px; width: 300px;" /></p>
6768

6869
<ul>
69-
<li>At level 1, nodes are processed left to right. Node 1 is included, thus <code>ans[0] = 1</code>.</li>
70-
<li>At level 2, nodes are processed right to left. Nodes 3 and 2 are included since both have right children, thus <code>ans[1] = 3 + 2 = 5</code>.</li>
71-
<li>At level 3, nodes are processed left to right. The first node 4 lacks a left child, so no nodes are included, and <code>ans[2] = 0</code>.</li>
72-
<li>Thus, <code>ans = [1, 5, 0]</code>.</li>
70+
<li>在第 1 层,从左往右处理节点。节点 1 被包含,因此&nbsp;<code>ans[0] = 1</code></li>
71+
<li>在第 2 层,从右往左处理节点。节点 3 和 2 被包含,因为它们都有右儿子,因此&nbsp;<code>ans[1] = 3 + 2 = 5</code></li>
72+
<li>在第 3 层,从左到右进行处理节点。第一个节点 4 没有左子节点,因此不包含任何节点,因此&nbsp;<code>ans[2] = 0</code></li>
73+
<li>因此,<code>ans = [1, 5, 0]</code>.</li>
7374
</ul>
7475
</div>
7576

7677
<p>&nbsp;</p>
77-
<p><strong>Constraints:</strong></p>
78+
79+
<p><strong>提示:</strong></p>
7880

7981
<ul>
80-
<li>The number of nodes in the tree is in the range <code>[1, 10<sup>5</sup>]</code>.</li>
82+
<li>树中的节点数范围为 <code>[1, 10<sup>5</sup>]</code></li>
8183
<li><code>-10<sup>5</sup> &lt;= Node.val &lt;= 10<sup>5</sup></code></li>
8284
</ul>
8385

solution/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3912,7 +3912,7 @@
39123912
| 3899 | [三角形的内角度数](/solution/3800-3899/3899.Angles%20of%20a%20Triangle/README.md) | | 中等 | 第 497 场周赛 |
39133913
| 3900 | [一次交换后的最长平衡子串](/solution/3900-3999/3900.Longest%20Balanced%20Substring%20After%20One%20Swap/README.md) | | 中等 | 第 497 场周赛 |
39143914
| 3901 | [好子序列查询](/solution/3900-3999/3901.Good%20Subsequence%20Queries/README.md) | | 困难 | 第 497 场周赛 |
3915-
| 3902 | [Zigzag Level Sum of Binary Tree](/solution/3900-3999/3902.Zigzag%20Level%20Sum%20of%20Binary%20Tree/README.md) | | 中等 | 🔒 |
3915+
| 3902 | [二叉树的 Z 字形层级和](/solution/3900-3999/3902.Zigzag%20Level%20Sum%20of%20Binary%20Tree/README.md) | | 中等 | 🔒 |
39163916

39173917
## 版权
39183918

solution/result.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)