<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Linked List on Yosgi</title><link>https://yosgi.github.io/en/tags/linked-list/</link><description>Recent content in Linked List on Yosgi</description><generator>Hugo</generator><language>en</language><lastBuildDate>Mon, 29 Jun 2026 09:20:51 +0000</lastBuildDate><atom:link href="https://yosgi.github.io/en/tags/linked-list/index.xml" rel="self" type="application/rss+xml"/><item><title>Reverse Linked List 2</title><link>https://yosgi.github.io/en/post/reverse-linked-list-2/</link><pubDate>Fri, 23 Jul 2021 00:00:00 +1200</pubDate><guid>https://yosgi.github.io/en/post/reverse-linked-list-2/</guid><description>Considering that the head may also be reversed, a dummy head is needed. During the traversal process, the tail node after the reversal and the previous node are recorded. Finally, the node link processing is performed. var reverseBetween = function(head, m, n) { let noob = new ListNode(0) noob.next = head let cur = noob let index = 0 let A,B while (index &lt; m) { A = cur // A records the previous node of the reverse subchain cur = cur.next index++ } B = cur // B records the tail node after reversal let pre = cur while (index &lt;= n) { let next = cur.next cur.next = pre pre = cur cur = next index++ } // After execution, the cur pointer is at the next node of the reverse subchain B.next = cur A.next = pre return noob.next };</description></item><item><title>138-Copying a linked list with random pointers</title><link>https://yosgi.github.io/en/post/138-copying-a-linked-list-with-random-pointers/</link><pubDate>Thu, 22 Jul 2021 00:00:00 +1200</pubDate><guid>https://yosgi.github.io/en/post/138-copying-a-linked-list-with-random-pointers/</guid><description>The idea behind the question is to use double pointers to point to the old and new nodes, and then add a map to map the old and new nodes. recursion var listMap = new Map() var copyRandomList = function(head) { if(head === null) return head if (listMap.get(head)) { return listMap.get(head) } let newNode = new Node(head.val,null,null) listMap.set(head, newNode) newNode.next = copyRandomList(head.next) newNode.random = copyRandomList(head.random) return newNode }; ```Iteration ```javascript var copyRandomList = function(head) { if(head == null) return head var listMap = new Map() listMap.set(null,null) var cur = head while (cur!= null) { listMap.set(cur,new Node(cur.val,null,null)) cur = cur.next } cur = head while (cur!= null) { listMap.get(cur).next = listMap.get(cur.next) listMap.get(cur).random = listMap.get(cur.random) cur = cur.next } return listMap.get(head) };The idea behind the question is to use double pointers to point to the old and new nodes, and then add a map to map the old and new nodes.</description></item></channel></rss>