leetcode 之Copy List with Random Pointer(23)
2016-05-21 15:29
381 查看
RandomListNode *randomList(RandomListNode *head) { //复制每个结点,并将新结点放在旧结点之后 for (RandomListNode *cur = head; cur != nullptr;) { RandomListNode *node = new RandomListNode(cur->label); node->next = cur->next; cur->next = node; cur = node->next; } //修改新结点的Random指针 for (RandomListNode *cur = head; cur != nullptr;) { if (cur->random != nullptr)cur->next->random = cur->random->next; cur = cur->next->next; } //将新旧链表断开 RandomListNode dummy(-1); for (RandomListNode *cur = head,*new_cur=&dummy; cur != nullptr;) { new_cur->next = cur->next; new_cur = new_cur->next; cur->next = cur->next->next; cur = cur->next; } return dummy.next; }
View Code
相关文章推荐
- Linux基础知识总结(一)
- 学生管理系统(三层架构)
- 内存操作函数memcopy和memmove
- Tomcat学习之Context
- 第二部分 s3c2440 移植linux内核 添加网卡支持 yaffs2文件系统支持
- 《Linux命令行与shell脚本》笔记--第3章:基本的bash shell命令
- [问题] mac执行git命令出现xcrun: error: invalid active developer path解决方法
- dopost doget区别
- linux中vim、gcc、gdb
- Java线程池架构2-多线程调度器(ScheduledThreadPoolExecutor)
- 安装 openSUSE Leap 42.1 之后要做的 8 件事
- 基本的OpenGL语法及其相关的知识。
- 《Linux命令行与shell脚本》笔记--第2章:走进shell
- ORM methods odoo openerp 主类的主要的几个方法
- nginx url遇到的问题
- docker公开课记录
- Linux命令之echo,printf-2
- postgresql 在linux上的源码安装
- dlib、opencv - 人脸关键点定位
- github使用(linux)