LoginSignup
0
0

More than 1 year has passed since last update.

Leetcode 1470. Shuffle the Array

Posted at

アプローチ

Brute-force

class Solution {
    public int[] shuffle(int[] nums, int n) {
        int[] result = new int[nums.length];
        int start = 0;
        for (int i = 0; i < nums.length; i++) {
            if (i % 2 == 0) {
                result[i] = nums[start];
                start++;
            } else {
                result[i] = nums[n];
                n++;
            }
        }
        return result;
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0