Skip to content

Commit f1a94c6

Browse files
committed
Concatenation of Array
1 parent e6b597a commit f1a94c6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

1929-concatenation-of-array.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
Problem Link: https://leetcode.com/problems/concatenation-of-array/
3+
4+
Given an integer array nums of length n, you want to create an array ans of length 2n where ans[i] == nums[i] and
5+
ans[i + n] == nums[i] for 0 <= i < n (0-indexed).
6+
Specifically, ans is the concatenation of two nums arrays.
7+
Return the array ans.
8+
9+
Example 1:
10+
Input: nums = [1,2,1]
11+
Output: [1,2,1,1,2,1]
12+
Explanation: The array ans is formed as follows:
13+
- ans = [nums[0],nums[1],nums[2],nums[0],nums[1],nums[2]]
14+
- ans = [1,2,1,1,2,1]
15+
16+
Example 2:
17+
Input: nums = [1,3,2,1]
18+
Output: [1,3,2,1,1,3,2,1]
19+
Explanation: The array ans is formed as follows:
20+
- ans = [nums[0],nums[1],nums[2],nums[3],nums[0],nums[1],nums[2],nums[3]]
21+
- ans = [1,3,2,1,1,3,2,1]
22+
23+
Constraints:
24+
n == nums.length
25+
1 <= n <= 1000
26+
1 <= nums[i] <= 1000
27+
"""
28+
class Solution:
29+
def getConcatenation(self, nums: List[int]) -> List[int]:
30+
l = len(nums)
31+
for index in range(l):
32+
nums.append(nums[index])
33+
34+
return nums

0 commit comments

Comments
 (0)