0 效果
1 题目
2 思路
简单的数组或向量操作。
3 代码
C++:
class Solution {
public:
vector<int> shuffle(vector<int>& nums, int n) {
vector<int> c;
for (int i = 0; i < n; ++i) {
c.push_back(nums[i]);
c.push_back(nums[i+n]);
}
return c;
}
};
C
int* shuffle(int* nums, int numsSize, int n, int* returnSize){
int* p = (int*) malloc(sizeof(int) * n * 2);
for(int i = 0, j = 0;i < n;i++){
*(p + (j++)) = *(nums + i);
*(p + (j++)) = *(nums + i + n);
}
*returnSize = 2 * n;
return p;
}