-
Notifications
You must be signed in to change notification settings - Fork 7
/
1470.cpp
44 lines (38 loc) · 808 Bytes
/
1470.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//Solution 1
class Solution
{
public:
vector<int> shuffle(vector<int> &nums, int n)
{
vector<int> v1, v2;
int index = 0;
int siz = nums.size() / 2;
for (int i = 0; i < siz; i++)
{
v1.push_back(nums[i]);
v2.push_back(nums[i + n]);
}
nums.clear();
for (index = 0; index < siz; index++)
{
nums.push_back(v1[index]);
nums.push_back(v2[index]);
}
return nums;
}
};
//Solution 2
class Solution
{
public:
vector<int> shuffle(vector<int> &nums, int n)
{
vector<int> ans;
for (int i = 0; i < nums.size() / 2; i++)
{
ans.push_back(nums[i]);
ans.push_back(nums[i + n]);
}
return ans;
}
};