Skip to content

Commit d77cf0f

Browse files
committed
algorihm [fiqqar] adding new algorithm {concatination array}
1 parent a71618f commit d77cf0f

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

concate_array/arr.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from typing import List
2+
3+
class Solution:
4+
def getConcatenation(self, nums: List[int]) -> List[int]:
5+
l = len(nums)
6+
res = [0] * (2 * l)
7+
for i in range(l):
8+
res[i] = nums[i]
9+
res[i+l] = nums[i]
10+
return res
11+

concate_array/readme.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<h2>>Concatenation of Array</a></h2><h3>Easy</h3><hr><p>Given an integer array</code> of length <code>n</code>, you want to create an array <code>ans</code> of length <code>2n</code> where <code>ans[i] == nums[i]</code> and <code>ans[i + n] == nums[i]</code> for <code>0 &lt;= i &lt; n</code> (<strong>0-indexed</strong>).</p>
2+
3+
<p>Specifically, <code>ans</code> is the <strong>concatenation</strong> of two <code>nums</code> arrays.</p>
4+
5+
<p>Return <em>the array </em><code>ans</code>.</p>
6+
7+
<p>&nbsp;</p>
8+
<p><strong class="example">Example 1:</strong></p>
9+
10+
<pre>
11+
<strong>Input:</strong> nums = [1,2,1]
12+
<strong>Output:</strong> [1,2,1,1,2,1]
13+
<strong>Explanation:</strong> The array ans is formed as follows:
14+
- ans = [nums[0],nums[1],nums[2],nums[0],nums[1],nums[2]]
15+
- ans = [1,2,1,1,2,1]</pre>
16+
17+
<p><strong class="example">Example 2:</strong></p>
18+
19+
<pre>
20+
<strong>Input:</strong> nums = [1,3,2,1]
21+
<strong>Output:</strong> [1,3,2,1,1,3,2,1]
22+
<strong>Explanation:</strong> The array ans is formed as follows:
23+
- ans = [nums[0],nums[1],nums[2],nums[3],nums[0],nums[1],nums[2],nums[3]]
24+
- ans = [1,3,2,1,1,3,2,1]
25+
</pre>
26+
27+
<p>&nbsp;</p>
28+
<p><strong>Constraints:</strong></p>
29+
30+
<ul>
31+
<li><code>n == nums.length</code></li>
32+
<li><code>1 &lt;= n &lt;= 1000</code></li>
33+
<li><code>1 &lt;= nums[i] &lt;= 1000</code></li>
34+
</ul>

0 commit comments

Comments
 (0)