leetcode之Populating Next Right Pointers in Each Node
来源:互联网 发布:centos下的java环境 编辑:程序博客网 时间:2024/06/03 17:18
这题就是在正常的广度优先搜索的栈里面加上了链表指向。比较简单的一道题。代码如下:
# Definition for binary tree with next pointer.# class TreeLinkNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = None# self.next = Noneclass Solution(object): def connect(self, root): """ :type root: TreeLinkNode :rtype: nothing """ if not root: return root a = [root] b = [] while a != []: for i in a: if i.left: b.append(i.left) if i.right: b.append(i.right) if b != []: for i in range(len(b) - 1): b[i].next = b[i + 1] a = b b = []
0 0
- LeetCode 之 Populating Next Right Pointers in Each Node
- LeetCode 之 Populating Next Right Pointers in Each Node II
- leetcode之Populating Next Right Pointers in Each Node
- LeetCode之Populating Next Right Pointers in Each Node II
- LeetCode之Populating Next Right Pointers in Each Node
- leetcode之Populating Next Right Pointers in Each Node
- leetcode之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 &&Populating Next Right Pointers in Each Node||
- LeetCode Populating Next Right Pointers in Each Node & Populating Next Right Pointers in Each Node I
- 【Leetcode】Populating Next Right Pointers in Each Node in JAVA
- LeetCode Populating Next Right Pointers in Each Node
- LeetCode Populating Next Right Pointers in Each Node II
- [Leetcode] Populating Next Right Pointers in Each Node
- LeetCode: Populating Next Right Pointers in Each Node
- [Leetcode] Populating Next Right Pointers in Each Node II
- [LeetCode] Populating Next Right Pointers in Each Node
- [LeetCode] Populating Next Right Pointers in Each Node II
- 在VMWARE虚拟机中的linux(centos)系统安装VMware tools的方法
- linux下声卡编程
- 关于排序算法
- 第一部分 Hibernate入门
- SQL Server XML 入门 基础
- leetcode之Populating Next Right Pointers in Each Node
- Android 4.4(API 19)闹钟管理与计步器功能
- matlab中find函数的使用说明
- 第二部分 Hibernate的基本配置
- CALayer - 11
- Thrift入门及Java实例
- 如何使用.htaccess重定向网站多个目录
- MASM汇编语言程序设计之---段的规划设计(一)
- Android 百度地图经纬度转换成地址