package com.算法专练.力扣.重新排列数组;
/**
* @author xnl
* @Description:
* @date: 2022/8/29 22:14
*/
public class Solution {
public static void main(String[] args) {
Solution solution = new Solution();
}
/**
* 一次遍历,加数组数值,时间和空间负责度都是logn
* @param nums
* @param n
* @return
*/
public int[] shuffle(int[] nums, int n) {
int[] clone = new int[n * 2];
for (int i = 0; i < n ;i ++){
clone[i * 2] = nums[i];
clone[i * 2 + 1] = nums[n + i];
}
return clone;
}
}
力扣:1470. 重新排列数组
最新推荐文章于 2024-11-04 12:20:00 发布