thiagowfx's avatar

Β¬ just serendipity πŸ€ (not just serendipity)

LeetCode #1929: Concatenation of Array

β€’ 95 words β€’ 1 min β€’ updated

LeetCode #1929: Concatenation of Array:

Various ways to concatenate:

python
class Solution:
    def getConcatenation(self, nums: List[int]) -> List[int]:
        return nums * 2
python
class Solution:
    def getConcatenation(self, nums: List[int]) -> List[int]:
        return [n for n in nums] + [n for n in nums]
python
class Solution:
    def getConcatenation(self, nums: List[int]) -> List[int]:
        return nums + nums
python
class Solution:
    def getConcatenation(self, nums: List[int]) -> List[int]:
        for n in nums[:]:
            nums.append(n)
        return nums
python
class Solution:
    def getConcatenation(self, nums: List[int]) -> List[int]:
        ans = []
        for _ in range(2):
            for n in nums:
                ans.append(n)
        return ans