https://leetcode.com/problems/concatenation-of-array/description/
class Solution:
def getConcatenation(self, nums: List[int]) -> List[int]:
ans = [n for n in nums] + [n for n in nums]
return ans
class Solution:
def getConcatenation(self, nums: List[int]) -> List[int]:
return nums + nums
class Solution:
def getConcatenation(self, nums: List[int]) -> List[int]:
n = len(nums)
ans = [0] * (2 * n)
for i, num in enumerate(nums):
ans[i] = ans[i + n] = num
return ans
Time & Space Complexity
- Time complexity: O(n)
- Space complexity: O(n) for the output array.
'LeetCode > NeetCode' 카테고리의 다른 글
| 1472. Design Browser History (0) | 2025.03.30 |
|---|---|
| 707. Design Linked List (0) | 2025.03.30 |
| 27. Remove Element (0) | 2025.03.30 |
| [Two Pointers] 26. Remove Duplicates from Sorted Array (0) | 2025.03.30 |
| Sorting: 75. Sort Colors (0) | 2025.02.04 |