<?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>concatenation Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/concatenation/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/concatenation/</link>
	<description></description>
	<lastBuildDate>Sun, 12 Feb 2023 16:03:41 +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>concatenation Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/concatenation/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 2562. Find the Array Concatenation Value</title>
		<link>https://zxi.mytechroad.com/blog/algorithms/array/leetcode-2562-find-the-array-concatenation-value/</link>
					<comments>https://zxi.mytechroad.com/blog/algorithms/array/leetcode-2562-find-the-array-concatenation-value/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 12 Feb 2023 16:03:16 +0000</pubDate>
				<category><![CDATA[Array]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[concatenation]]></category>
		<category><![CDATA[easy]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=9936</guid>

					<description><![CDATA[<p>You are given a&#160;0-indexed&#160;integer array&#160;nums. The&#160;concatenation&#160;of two numbers is the number formed by concatenating their numerals. For example, the concatenation of&#160;15,&#160;49&#160;is&#160;1549. The&#160;concatenation value&#160;of&#160;nums&#160;is initially equal&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/algorithms/array/leetcode-2562-find-the-array-concatenation-value/">花花酱 LeetCode 2562. Find the Array Concatenation Value</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 a&nbsp;<strong>0-indexed</strong>&nbsp;integer array&nbsp;<code>nums</code>.</p>



<p>The&nbsp;<strong>concatenation</strong>&nbsp;of two numbers is the number formed by concatenating their numerals.</p>



<ul><li>For example, the concatenation of&nbsp;<code>15</code>,&nbsp;<code>49</code>&nbsp;is&nbsp;<code>1549</code>.</li></ul>



<p>The&nbsp;<strong>concatenation value</strong>&nbsp;of&nbsp;<code>nums</code>&nbsp;is initially equal to&nbsp;<code>0</code>. Perform this operation until&nbsp;<code>nums</code>&nbsp;becomes empty:</p>



<ul><li>If there exists more than one number in&nbsp;<code>nums</code>, pick the first element and last element in&nbsp;<code>nums</code>&nbsp;respectively and add the value of their concatenation to the&nbsp;<strong>concatenation value</strong>&nbsp;of&nbsp;<code>nums</code>, then delete the first and last element from&nbsp;<code>nums</code>.</li><li>If one element exists, add its value to the&nbsp;<strong>concatenation value</strong>&nbsp;of&nbsp;<code>nums</code>, then delete it.</li></ul>



<p>Return<em>&nbsp;the concatenation value of the&nbsp;<code>nums</code></em>.</p>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> nums = [7,52,2,4]
<strong>Output:</strong> 596
<strong>Explanation:</strong> Before performing any operation, nums is [7,52,2,4] and concatenation value is 0.
 - In the first operation:
We pick the first element, 7, and the last element, 4.
Their concatenation is 74, and we add it to the concatenation value, so it becomes equal to 74.
Then we delete them from nums, so nums becomes equal to [52,2].
 - In the second operation:
We pick the first element, 52, and the last element, 2.
Their concatenation is 522, and we add it to the concatenation value, so it becomes equal to 596.
Then we delete them from the nums, so nums becomes empty.
Since the concatenation value is 596 so the answer is 596.
</pre>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> nums = [5,14,13,8,12]
<strong>Output:</strong> 673
<strong>Explanation:</strong> Before performing any operation, nums is [5,14,13,8,12] and concatenation value is 0.
 - In the first operation:
We pick the first element, 5, and the last element, 12.
Their concatenation is 512, and we add it to the concatenation value, so it becomes equal to 512.
Then we delete them from the nums, so nums becomes equal to [14,13,8].
 - In the second operation:
We pick the first element, 14, and the last element, 8.
Their concatenation is 148, and we add it to the concatenation value, so it becomes equal to 660.
Then we delete them from the nums, so nums becomes equal to [13].
 - In the third operation:
nums has only one element, so we pick 13 and add it to the concatenation value, so it becomes equal to 673.
Then we delete it from nums, so nums become empty.
Since the concatenation value is 673 so the answer is 673.
</pre>



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



<ul><li><code>1 &lt;= nums.length &lt;= 1000</code></li><li><code>1 &lt;= nums[i] &lt;= 10<sup>4</sup></code></li></ul>



<h2><strong>Solution: Follow the rules</strong></h2>



<p>Time complexity: O(sum(log(nums[i]))<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:
  long long findTheArrayConcVal(vector&lt;int&gt;&amp; nums) {
    long long ans = 0;
    const int n = nums.size();
    for (int i = 0; i &lt; n / 2; ++i) {
      int cur  = nums[i];
      for (int t = nums[n - i - 1]; t &gt; 0; t /= 10)
        cur *= 10;    
      cur += nums[n - i - 1];
      ans += cur;
    }          
    if (n &amp; 1) ans += nums[n / 2];
    return ans;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/algorithms/array/leetcode-2562-find-the-array-concatenation-value/">花花酱 LeetCode 2562. Find the Array Concatenation Value</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/algorithms/array/leetcode-2562-find-the-array-concatenation-value/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>花花酱 LeetCode 1662. Check If Two String Arrays are Equivalent</title>
		<link>https://zxi.mytechroad.com/blog/string/leetcode-1662-check-if-two-string-arrays-are-equivalent/</link>
					<comments>https://zxi.mytechroad.com/blog/string/leetcode-1662-check-if-two-string-arrays-are-equivalent/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 22 Nov 2020 08:30:11 +0000</pubDate>
				<category><![CDATA[String]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[concatenation]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[string]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=7696</guid>

					<description><![CDATA[<p>Given two string arrays&#160;word1&#160;and&#160;word2, returntrue&#160;if the two arrays&#160;represent&#160;the same string, and&#160;false&#160;otherwise. A string is&#160;represented&#160;by an array if the array elements concatenated&#160;in order&#160;forms the string. Example&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/string/leetcode-1662-check-if-two-string-arrays-are-equivalent/">花花酱 LeetCode 1662. Check If Two String Arrays are Equivalent</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>Given two string arrays&nbsp;<code>word1</code>&nbsp;and&nbsp;<code>word2</code>, return<code>true</code><em>&nbsp;if the two arrays&nbsp;<strong>represent</strong>&nbsp;the same string, and&nbsp;</em><code>false</code><em>&nbsp;otherwise.</em></p>



<p>A string is&nbsp;<strong>represented</strong>&nbsp;by an array if the array elements concatenated&nbsp;<strong>in order</strong>&nbsp;forms the string.</p>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> word1 = ["ab", "c"], word2 = ["a", "bc"]
<strong>Output:</strong> true
<strong>Explanation:</strong>
word1 represents string "ab" + "c" -&gt; "abc"
word2 represents string "a" + "bc" -&gt; "abc"
The strings are the same, so return true.</pre>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> word1 = ["a", "cb"], word2 = ["ab", "c"]
<strong>Output:</strong> false
</pre>



<p><strong>Example 3:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> word1  = ["abc", "d", "defg"], word2 = ["abcddefg"]
<strong>Output:</strong> true
</pre>



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



<ul><li><code>1 &lt;= word1.length, word2.length &lt;= 10<sup>3</sup></code></li><li><code>1 &lt;= word1[i].length, word2[i].length &lt;= 10<sup>3</sup></code></li><li><code>1 &lt;= sum(word1[i].length), sum(word2[i].length) &lt;= 10<sup>3</sup></code></li><li><code>word1[i]</code>&nbsp;and&nbsp;<code>word2[i]</code>&nbsp;consist of lowercase letters.</li></ul>



<h2><strong>Solution1: Construct the string</strong></h2>



<p>Time complexity: O(l1 + l2)<br>Space complexity: O(l1 + l2)</p>



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

<pre class="crayon-plain-tag">class Solution {
public:
  bool arrayStringsAreEqual(vector&lt;string&gt;&amp; word1, vector&lt;string&gt;&amp; word2) {
    string s1, s2;
    for (const string&amp; w1 : word1) s1 += w1;
    for (const string&amp; w2 : word2) s2 += w2;
    return s1 == s2;
  }
};</pre>
</div></div>



<h2><strong>Solution 2: Pointers</strong></h2>



<p>Time complexity: O(l1 + l2)<br>Space complexity: O(1)</p>



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

<pre class="crayon-plain-tag">class Solution {
public:
  bool arrayStringsAreEqual(vector&lt;string&gt;&amp; word1, vector&lt;string&gt;&amp; word2) {
    int i1 = 0, j1 = 0;
    int i2 = 0, j2 = 0;
    while (i1 &lt; word1.size() || i2 &lt; word2.size()) {
      char c1 = i1 &lt; word1.size() ? word1[i1][j1++] : '\0';
      char c2 = i2 &lt; word2.size() ? word2[i2][j2++] : '\0';
      if (c1 != c2) return false;
      if (i1 &lt; word1.size() &amp;&amp; j1 == word1[i1].length())
        ++i1, j1 = 0;
      if (i2 &lt; word2.size() &amp;&amp; j2 == word2[i2].length())
        ++i2, j2 = 0;
    }
    return true;
  }
};</pre>
</div></div>



<p></p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/string/leetcode-1662-check-if-two-string-arrays-are-equivalent/">花花酱 LeetCode 1662. Check If Two String Arrays are Equivalent</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/string/leetcode-1662-check-if-two-string-arrays-are-equivalent/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
