leetcode_middle_78_117. Populating Next Right Pointers in Each Node II
来源:互联网 发布:手机自动播音软件 编辑:程序博客网 时间:2024/06/06 14:12
题意:
给一个二叉树,将其next指针设置为其水平右边相邻的那个结点,没有则设置为空
分析:
the code which i wrote for the 116 still work.
/** * Definition for binary tree with next pointer. * public class TreeLinkNode { * int val; * TreeLinkNode left, right, next; * TreeLinkNode(int x) { val = x; } * } */public class Solution { public void connect(TreeLinkNode root) { Queue<TreeLinkNode> q = new LinkedList<>(); if(root == null) return; q.offer(root); while(!q.isEmpty()){ int size = q.size(); for(int i=0; i<size; i++){ TreeLinkNode node = q.poll(); if(i != size-1) node.next = q.peek(); if(node.left != null){ q.offer(node.left); } if(node.right != null){ q.offer(node.right); } } } }}
0 0
- leetcode_middle_78_117. Populating Next Right Pointers in Each Node II
- Populating Next Right Pointers in Each Node、Populating Next Right Pointers in Each Node II
- 【LeetCode】Populating Next Right Pointers in Each Node Populating Next Right Pointers in Each Node II
- LeetCode Populating Next Right Pointers in Each Node II
- [Leetcode] Populating Next Right Pointers in Each Node II
- [LeetCode] Populating Next Right Pointers in Each Node II
- leetcode 79: Populating Next Right Pointers in Each Node II
- [Leetcode] Populating Next Right Pointers in Each Node ii
- leetcode Populating Next Right Pointers in Each Node II
- 【leetcode】Populating Next Right Pointers in Each Node II
- Populating Next Right Pointers in Each Node II
- Populating Next Right Pointers in Each Node II
- Populating Next Right Pointers in Each Node II
- Populating Next Right Pointers in Each Node II
- Populating Next Right Pointers in Each Node II
- [Leetcode]Populating Next Right Pointers in Each Node II
- Populating Next Right Pointers in Each Node II
- Populating Next Right Pointers in Each Node (I & II)
- SqueezeNet运用到Faster RCNN进行目标检测
- javaScript中的BOM对象-Location(2)
- RPC框架的原理及实践 ,为什么说要搞定微服务架构,先搞定RPC框架呢
- 关于公式编辑器mathpage.wll文件未找到的解决方案
- spring boot 实际应用(一) 内置tomcat 实现JMX配置
- leetcode_middle_78_117. Populating Next Right Pointers in Each Node II
- 人月神话
- Traefik-kubernetes 负责均衡器初试
- Spark应用(二) 二次排序
- 备份脚本
- C++/C 字符串拼接
- EditText 相关知识点
- sh, 批量执行Linux命令
- 互联网架构为什么要做服务化