LeetCode 314. Binary Tree Vertical Order Traversal - 二叉树(Binary Tree)系列题6

本博客介绍了LeetCode 314题的解决方案,涉及二叉树的垂直顺序遍历。文章通过示例解释了如何从上到下,按列对节点进行遍历,当节点在同一列时,遵循从左到右的顺序。内容涵盖了题目要求、算法思路以及具体的实现方法,包括如何给节点分配列号,并利用水平遍历来构建最终的二维结果数组。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Given the root of a binary tree, return the vertical order traversal of its nodes' values. (i.e., from top to bottom, column by column).

If two nodes are in the same row and column, the order should be from left to right.

Example 1:

Input: root = [3,9,20,null,null,15,7]
Output: [[9],[3,15],[20],[7]]

Example 2:

Input: root = [3,9,8,4,0,1,7]
Output: [[4],[9],[3,0,1],[8],[7]]

Example 3:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值