Skip to content

Commit 08d4ed0

Browse files
author
Saidev
committed
Added "04-Concatenation of Array.py" problem solution
1 parent c3b51f1 commit 08d4ed0

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

04-Concatenation of Array.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'''
2+
Example 1:
3+
4+
Input: nums = [1,2,1]
5+
Output: [1,2,1,1,2,1]
6+
Explanation: The array ans is formed as follows:
7+
- ans = [nums[0],nums[1],nums[2],nums[0],nums[1],nums[2]]
8+
- ans = [1,2,1,1,2,1]
9+
10+
Example 2:
11+
12+
Input: nums = [1,3,2,1]
13+
Output: [1,3,2,1,1,3,2,1]
14+
Explanation: The array ans is formed as follows:
15+
- ans = [nums[0],nums[1],nums[2],nums[3],nums[0],nums[1],nums[2],nums[3]]
16+
- ans = [1,3,2,1,1,3,2,1]
17+
'''
18+
19+
def getConcatenation(self, nums):
20+
# return nums*2 (or)
21+
# return nums + nums (or)
22+
nums.extend(nums)
23+
return nums
24+
25+
nums = [1,2,1]
26+
print(getConcatenation(nums))
27+
28+
nums = [1,3,2,1]
29+
print(getConcatenation(nums))

0 commit comments

Comments
 (0)