当前位置: 首页> 科技> 互联网 > seo中文全称是什么_推广公司名称_企业员工培训课程内容_百度引流免费推广怎么做

seo中文全称是什么_推广公司名称_企业员工培训课程内容_百度引流免费推广怎么做

时间:2025/9/10 9:57:29来源:https://blog.csdn.net/2401_88859777/article/details/144442232 浏览次数:1次
seo中文全称是什么_推广公司名称_企业员工培训课程内容_百度引流免费推广怎么做

问题背景

给你二叉树的根节点 r o o t root root,返回其节点值的 层序遍历 。 (即逐层地,从左到右访问所有节点)。

数据约束

  • 树中节点数目在范围 [ 0 , 2000 ] [0, 2000] [0,2000]
  • − 1000 ≤ N o d e . v a l ≤ 1000 -1000 \le Node.val \le 1000 1000Node.val1000

解题过程

二叉树的层序遍历,用栈来辅助实现,当成模板来记。

具体实现

/*** Definition for a binary tree node.* public class TreeNode {*     int val;*     TreeNode left;*     TreeNode right;*     TreeNode() {}*     TreeNode(int val) { this.val = val; }*     TreeNode(int val, TreeNode left, TreeNode right) {*         this.val = val;*         this.left = left;*         this.right = right;*     }* }*/
class Solution {public List<List<Integer>> levelOrder(TreeNode root) {List<List<Integer>> res = new ArrayList<>();if(root == null) {return res;}Queue<TreeNode> queue = new LinkedList<>();queue.offer(root);while(!queue.isEmpty()) {int n = queue.size();List<Integer> list = new ArrayList(n);while(n-- != 0) {TreeNode cur = queue.poll();list.add(cur.val);if(cur.left != null) {queue.add(cur.left);}if(cur.right != null) {queue.add(cur.right);}}res.add(list);}return res;}
}
关键字:seo中文全称是什么_推广公司名称_企业员工培训课程内容_百度引流免费推广怎么做

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: