Concatenation of Array — LeetCode 1929 Python Solution
EasyArraySimulation
- Problem
- #1929
- 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
Python
class Solution:
def getConcatenation(self, nums: List[int]) -> List[int]:
return nums + numsComplexity
| Measure | Complexity |
|---|---|
| Time | O(n) |
| Space | O(n) auxiliary |
Related problems
LeetCode 1920Build Array from PermutationEasyLeetCode 495Teemo AttackingEasyLeetCode 985Sum of Even Numbers After QueriesMediumLeetCode 1389Create Target Array in the Given OrderEasyLeetCode 1409Queries on a Permutation With KeyMediumLeetCode 1503Last Moment Before All Ants Fall Out of a PlankMedium
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.