<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>tail Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/tail/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/tail/</link>
	<description></description>
	<lastBuildDate>Sat, 28 Nov 2020 19:08:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.8</generator>

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>tail Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/tail/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 1669. Merge In Between Linked Lists</title>
		<link>https://zxi.mytechroad.com/blog/list/leetcode-1669-merge-in-between-linked-lists/</link>
					<comments>https://zxi.mytechroad.com/blog/list/leetcode-1669-merge-in-between-linked-lists/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sat, 28 Nov 2020 19:07:25 +0000</pubDate>
				<category><![CDATA[List]]></category>
		<category><![CDATA[dummy head]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[medium]]></category>
		<category><![CDATA[prev]]></category>
		<category><![CDATA[tail]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=7722</guid>

					<description><![CDATA[<p>You are given two linked lists:&#160;list1&#160;and&#160;list2&#160;of sizes&#160;n&#160;and&#160;m&#160;respectively. Remove&#160;list1&#8216;s nodes from the&#160;ath&#160;node to the&#160;bth&#160;node, and put&#160;list2&#160;in their place. The blue edges and nodes in the following&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/list/leetcode-1669-merge-in-between-linked-lists/">花花酱 LeetCode 1669. Merge In Between Linked Lists</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>You are given two linked lists:&nbsp;<code>list1</code>&nbsp;and&nbsp;<code>list2</code>&nbsp;of sizes&nbsp;<code>n</code>&nbsp;and&nbsp;<code>m</code>&nbsp;respectively.</p>



<p>Remove&nbsp;<code>list1</code>&#8216;s nodes from the&nbsp;<code>a<sup>th</sup></code>&nbsp;node to the&nbsp;<code>b<sup>th</sup></code>&nbsp;node, and put&nbsp;<code>list2</code>&nbsp;in their place.</p>



<p>The blue edges and nodes in the following figure incidate the result:</p>



<figure class="wp-block-image"><img src="https://assets.leetcode.com/uploads/2020/11/05/fig1.png" alt=""/></figure>



<p><em>Build the result list and return its head.</em></p>



<p><strong>Example 1:</strong></p>



<figure class="wp-block-image"><img src="https://assets.leetcode.com/uploads/2020/11/05/merge_linked_list_ex1.png" alt=""/></figure>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> list1 = [0,1,2,3,4,5], a = 3, b = 4, list2 = [1000000,1000001,1000002]
<strong>Output:</strong> [0,1,2,1000000,1000001,1000002,5]
<strong>Explanation:</strong> We remove the nodes 3 and 4 and put the entire list2 in their place. The blue edges and nodes in the above figure indicate the result.
</pre>



<p><strong>Example 2:</strong></p>



<figure class="wp-block-image"><img src="https://assets.leetcode.com/uploads/2020/11/05/merge_linked_list_ex2.png" alt=""/></figure>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> list1 = [0,1,2,3,4,5,6], a = 2, b = 5, list2 = [1000000,1000001,1000002,1000003,1000004]
<strong>Output:</strong> [0,1,1000000,1000001,1000002,1000003,1000004,6]
<strong>Explanation:</strong> The blue edges and nodes in the above figure indicate the result.
</pre>



<p><strong>Constraints:</strong></p>



<ul><li><code>3 &lt;= list1.length &lt;= 10<sup>4</sup></code></li><li><code>1 &lt;= a &lt;= b &lt; list1.length - 1</code></li><li><code>1 &lt;= list2.length &lt;= 10<sup>4</sup></code></li></ul>



<h2><strong>Solution: List Operations</strong></h2>



<p>Find the following nodes:<br>1. previous node to the a-th node: prev_a<br>2. the b-th node: node_b<br>3. tail node of list2: tail2<br><br>prev_a-&gt;next = list2<br>tail2-&gt;next = node_b<br><br>return list1</p>



<p>Time complexity: O(m+n)<br>Space complexity: O(1)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  ListNode* mergeInBetween(ListNode* list1, int a, int b, ListNode* list2) {
    ListNode dummy(0, list1);
    ListNode* prev_a = &amp;dummy;
    for (int i = 0; i &lt; a; ++i) prev_a = prev_a-&gt;next;
    ListNode* node_b = prev_a-&gt;next;
    for (int i = a; i &lt;= b; ++i) node_b = node_b-&gt;next;
    ListNode* tail2 = list2;
    while (tail2-&gt;next) tail2 = tail2-&gt;next;
    
    prev_a-&gt;next = list2;    
    tail2-&gt;next = node_b;
    return list1;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/list/leetcode-1669-merge-in-between-linked-lists/">花花酱 LeetCode 1669. Merge In Between Linked Lists</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/list/leetcode-1669-merge-in-between-linked-lists/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
