From 1747bdd5cc17b54532339b319b00653d2e657b72 Mon Sep 17 00:00:00 2001 From: Jidong Xiao Date: Thu, 14 Sep 2023 17:49:48 -0400 Subject: [PATCH] adding concatenation of array, use 2 loops, or use the copy constructor --- leetcode/l1929_concatenationofarray.cpp | 37 +++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 leetcode/l1929_concatenationofarray.cpp diff --git a/leetcode/l1929_concatenationofarray.cpp b/leetcode/l1929_concatenationofarray.cpp new file mode 100644 index 0000000..601ca93 --- /dev/null +++ b/leetcode/l1929_concatenationofarray.cpp @@ -0,0 +1,37 @@ +// basic approach: use two loops to generate the first half and the second half +/* +class Solution { +public: + vector getConcatenation(vector& nums) { + // use the default constructor + vector ans; + int size = nums.size(); + for(int i=0;i getConcatenation(vector& nums) { + // use the copy constructor + vector ans(nums); + int size = nums.size(); + // copy the second half + for(int i=0;i