430. Flatten a Multilevel Doubly Linked List
/*
// Definition for a Node.
class Node {
public:
int val = NULL;
Node* prev = NULL;
Node* next = NULL;
Node* child = NULL; Node() {} Node(int _val, Node* _prev, Node* _next, Node* _child) {
val = _val;
prev = _prev;
next = _next;
child = _child;
}
};
*/
class Solution {
public:
Node* flatten(Node* head) {
if (head == NULL) return head;
flatten2(head);
return head;
}
Node* flatten2(Node* head) { // flatten and return tail
Node* ret = head;
while (head) {
ret = head;
if (head->child) {
Node* tail = flatten2(head->child);
tail->next = head->next;
if (tail->next)
tail->next->prev = tail;
head->next = head->child;
head->next->prev = head;
head->child = NULL;
head = tail->next;
ret = tail;
}
else {
head = head->next;
}
}
return ret;
}
};
430. Flatten a Multilevel Doubly Linked List的更多相关文章
- 【LeetCode】430. Flatten a Multilevel Doubly Linked List 解题报告(Python)
		[LeetCode]430. Flatten a Multilevel Doubly Linked List 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: ... 
- LeetCode 430. Flatten a Multilevel Doubly Linked List
		原题链接在这里:https://leetcode.com/problems/flatten-a-multilevel-doubly-linked-list/description/ 题目: You a ... 
- [LC] 430. Flatten a Multilevel Doubly Linked List
		You are given a doubly linked list which in addition to the next and previous pointers, it could hav ... 
- LeetCode 430. Faltten a Multilevel Doubly Linked List
		题目链接:LeetCode 430. Faltten a Multilevel Doubly Linked List class Node { public: int val = NULL; Node ... 
- [LeetCode] Flatten a Multilevel Doubly Linked List 压平一个多层的双向链表
		You are given a doubly linked list which in addition to the next and previous pointers, it could hav ... 
- LeetCode 430:扁平化多级双向链表 Flatten a Multilevel Doubly Linked List
		您将获得一个双向链表,除了下一个和前一个指针之外,它还有一个子指针,可能指向单独的双向链表.这些子列表可能有一个或多个自己的子项,依此类推,生成多级数据结构,如下面的示例所示. 扁平化列表,使所有结点 ... 
- [LeetCode] Flatten Binary Tree to Linked List 将二叉树展开成链表
		Given a binary tree, flatten it to a linked list in-place. For example,Given 1 / \ 2 5 / \ \ 3 4 6 T ... 
- [LeetCode] 114. Flatten Binary Tree to Linked List 将二叉树展开成链表
		Given a binary tree, flatten it to a linked list in-place. For example,Given 1 / \ 2 5 / \ \ 3 4 6 T ... 
- Flatten Binary Tree to Linked List [LeetCode]
		Given a binary tree, flatten it to a linked list in-place. For example,Given 1 / \ 2 5 / \ \ 3 4 6 T ... 
随机推荐
- 启动和停止GlassFish Server
			您可以使用NetBeans IDE或命令行启动和停止GlassFish Server. 使用NetBeans IDE启动GlassFish Server 单击“服务”选项卡. 展开服务器. 右键单 ... 
- Servlet细节整合
			最近在复习Servlet,发现其中有很多细节方面的东西都没有接触到,只是学了大概 1.请求转发和请求重定向的区别 2.输入参数为中文时候的乱码问题 3.Web工程中的目录写法 下面分别阐述 1.请求转 ... 
- windows远程连接Mac、Mac远程连接Mac、Mac连接Windows
			最近因为要进行学习交流,需要用到远程连接,所以找了三种不同的方式,记录如下 1.Windows远程连接Mac 1.mac os x电脑设置 系统偏好设置-共享-勾选“远端管理”,然后在电脑设置—VNC ... 
- ps_cc:制作sprite拼贴图片
			我们的目标是: 将 合并为一张图片 step1:制作动作,便于批处理和重复使用 首先随便新建空白文档(建议:90x300px) 录制动作,alt+F9 上图中,可以新建分组前端,再新建动作 ... 
- oracle基本查询练习
			select * from regions; select * from countries; select * from locations; select * from departments; ... 
- Spring配置文件详细分析
			XML Schema命名空间作用: 1.避免命名冲突,像Java中的package一样 2.将不同作用的标签分门别类(像Spring中的tx命名空间针对事务类的标签,context命名空间针对组件的标 ... 
- c++ priority_queue
			1.默认为大顶堆 #include <iostream> #include <queue> using namespace std; int main() { priority ... 
- leetcode: 字符串
			1. palindrome-partitioning Given a string s, partition s such that every substring of the partition ... 
- java多线程安全
			class Ticket implements Runnable { public int sum=10; public void run() { while(true) { if(sum>0) ... 
- selenium 打开浏览器报错java.lang.NoSuchMethodError: org.openqa.selenium.chrome.ChromeOptions.addArguments([Ljava/lang/String;)
			java.lang.NoSuchMethodError: org.openqa.selenium.chrome.ChromeOptions.addArguments([Ljava/lang/Strin ... 
