leetcode 1470.重新排列数组

1.题目要求:

2.题目代码:

csharp 复制代码
class Solution {
public:
    vector<int> shuffle(vector<int>& nums, int n) {
        vector<int> x_array(nums.begin(),nums.begin() + n);
        vector<int> y_array(nums.begin() + n,nums.end());
        int x_index = 0;
        int y_index = 0;
        for(int i = 0;i < nums.size();i++){
            if(i % 2 == 0){
                nums[i] = x_array[x_index];
                x_index++;
            }else{
                nums[i] = y_array[y_index];
                y_index++;
            }
        }
        return nums;
    }
};
相关推荐
洛水水14 小时前
【力扣100题】81.寻找两个正序数组的中位数
数据结构·算法·leetcode
happymaker062614 小时前
LeetCodeHot100——155.最小栈
算法
洛水水14 小时前
【力扣100题】85.每日温度
算法·leetcode·职场和发展
Coder-magician15 小时前
《代码随想录》刷题打卡day15:二叉树part05
数据结构·c++·算法
Kurisu_红莉栖15 小时前
力扣56合并区间
算法·leetcode
Darling噜啦啦15 小时前
二叉树与递归算法实战:从树结构到 LeetCode 爬楼梯,一文吃透前端数据结构与递归思维
前端·javascript·数据结构
Irissgwe15 小时前
算法的时间复杂度和空间复杂度
数据结构·c++·算法·c·时间复杂度·空间复杂度
随意起个昵称15 小时前
区间dp-基础题目3(永别)
c++·算法
周末也要写八哥15 小时前
有向图Hierholzer算法的另一种实现
算法
bIo7lyA8v15 小时前
算法调优中的性能回归与基准测试分析的技术8
算法·数据挖掘·回归