EasyNo. 1929
Concatenation of Array — LeetCode 1929 Python Solution
- Topics
- Array, Simulation
- Reading time
- 2 min
- Source
- leetcode.com
The problem
Given an integer array nums of length n, you want to create an array ans of length 2n where ans[i] == nums[i] and ans[i + n] == nums[i] for 0 <= i < n (0-indexed). Specifically, ans is the concatenation of two nums arrays.
Example
- Input
- nums = [1,2,1]
- Output
- [1,2,1,1,2,1]
- Explanation
- The array ans is formed as follows:
Python solution
class Solution:
def getConcatenation(self, nums: List[int]) -> List[int]:
return nums + numsComplexity
- Time
- O(n)
- Space · auxiliary
- O(n)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 1920 | Build Array from Permutation | Easy |
| 0495 | Teemo Attacking | Easy |
| 0985 | Sum of Even Numbers After Queries | Medium |
| 1389 | Create Target Array in the Given Order | Easy |
| 1409 | Queries on a Permutation With Key | Medium |
| 1503 | Last Moment Before All Ants Fall Out of a Plank | Medium |
Frequently asked questions
- How hard is LeetCode 1929. Concatenation of Array?
LeetCode 1929. Concatenation of Array is rated Easy on LeetCode.
- What is the time complexity of LeetCode 1929. Concatenation of Array?
The Python solution on this page runs in O(n).
- What is the space complexity of LeetCode 1929. Concatenation of Array?
The Python solution on this page uses O(n) auxiliary space.
- What topics does LeetCode 1929. Concatenation of Array cover?
LeetCode 1929. Concatenation of Array is tagged Array and Simulation on LeetCode.