博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
剑指Offer-25-复杂链表的复制
阅读量:3725 次
发布时间:2019-05-22

本文共 1176 字,大约阅读时间需要 3 分钟。

题目描述

输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点,另一个特殊指针指向任意一个节点),返回结果为复制后复杂链表的head。(注意,输出结果中请不要返回参数中的节点引用,否则判题程序会直接返回空)

/*public class RandomListNode {    int label;    RandomListNode next = null;    RandomListNode random = null;    RandomListNode(int label) {        this.label = label;    }}*/public class Solution {    public RandomListNode Clone(RandomListNode pHead)    {        if(pHead==null){            return null;        }        RandomListNode pCur = pHead;        while(pCur != null){            RandomListNode pNewNode = new RandomListNode(pCur.label);            pNewNode.next = pCur.next;            pCur.next = pNewNode;            pCur = pNewNode.next;        }        pCur = pHead;        while(pCur!=null){            if(pCur.random!=null){                pCur.next.random = pCur.random.next;            }            pCur = pCur.next.next;        }        pCur = pHead;        RandomListNode cur,head = pCur.next;        cur = head;        while(pCur!=null){            pCur.next = cur.next;            pCur = pCur.next;            if(pCur!=null){                cur.next = pCur.next;                cur = cur.next;            }        }        return head;    }}

 

 

转载地址:http://byonn.baihongyu.com/

你可能感兴趣的文章
2020-12-17L 数组最大值求法 && 01.01. 判定字符是否唯一***
查看>>
2020-12-18L前++与后++ && 在既定时间内完成作业的人数
查看>>
2020-12-19L 1394幸运数 && alert(fn(1))
查看>>
2020-12-19 Vue-15CLI3 && 箭头函数
查看>>
2020-12-20L 闭包作用域 && 1431. 拥有最多糖果的孩子
查看>>
2020-12-21L this && 1656. 设计有序流(不知道啥意思)
查看>>
2020-12-21 Vue-15-router
查看>>
2020-12-22L 16.17. 连续数列 && splice
查看>>
2020-12-23L面试题 10.01. 合并排序的数组*** 不知道为啥错了
查看>>
2020-12-24L && 1051. 高度检查器
查看>>
2020-12-25L && 1380. 矩阵中的幸运数
查看>>
2020-12-26L地址栏location && 1389按照既定顺序创建目标数组 && 1413逐步求和得到正数的最小值
查看>>
2020-12-27L 5621. 无法吃午餐的学生数量 && 1502. 判断能否形成等差数列 && 1512. 好数对的数目
查看>>
2020-12-30 && 31 && 统计最大组数目 && this指向
查看>>
2021-01-05 斐波那契数列
查看>>
2021-01-08-补2021-1-8之前的 && 1399. 统计最大组的数目 && Map&&reduce
查看>>
2021-01-19补1.10-1.18
查看>>
2021-01-09 TabBar案例
查看>>
2021-01-20---1.24 &&L 最大子序列和-贪心法和动态规划法
查看>>
2021-01-22-Promise的简单使用
查看>>