Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions solutions/1901-2000/1929-concatenation-of-array/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 1929. Concatenation of Array

[LeetCode problem 1929](https://leetcode.com/problems/concatenation-of-array/)

- **Difficulty**: Easy
- **Tags**: array, simulation

## Description

Given an integer array `nums` of length `n`, return an array `ans` of length
`2n` where `ans[i] == nums[i]` and `ans[i + n] == nums[i]` for `0 <= i < n`
(i.e. `nums` concatenated with itself).
13 changes: 13 additions & 0 deletions solutions/1901-2000/1929-concatenation-of-array/solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "solution.hpp"

namespace leetcode::p1929 {

std::vector<int> solve(const std::vector<int>& nums) {
std::vector<int> result;
result.reserve(nums.size() * 2);
result.insert(result.end(), nums.begin(), nums.end());
result.insert(result.end(), nums.begin(), nums.end());
return result;
}

} // namespace leetcode::p1929
10 changes: 10 additions & 0 deletions solutions/1901-2000/1929-concatenation-of-array/solution.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include <vector>

namespace leetcode::p1929 {

// optimized: O(n) time, O(n) space — append nums to a copy of itself.
std::vector<int> solve(const std::vector<int>& nums);

} // namespace leetcode::p1929
8 changes: 8 additions & 0 deletions solutions/1901-2000/1929-concatenation-of-array/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <catch2/catch_test_macros.hpp>

#include "solution.hpp"

TEST_CASE("Problem 1929", "[p1929]") {
CHECK(leetcode::p1929::solve({1, 2, 1}) == std::vector<int>{1, 2, 1, 1, 2, 1});
CHECK(leetcode::p1929::solve({1, 3, 2, 1}) == std::vector<int>{1, 3, 2, 1, 1, 3, 2, 1});
}
9 changes: 0 additions & 9 deletions swift/1929.swift

This file was deleted.

Loading