1470. Shuffle the Array Easy
1/**
2 * [1470] Shuffle the Array
3 *
4 * Given the array nums consisting of 2n elements in the form [x1,x2,...,xn,y1,y2,...,yn].
5 *
6 * Return the array in the form [x1,y1,x2,y2,...,xn,yn].
7 *
8 *
9 * Example 1:
10 *
11 *
12 * Input: nums = [2,5,1,3,4,7], n = 3
13 * Output: [2,3,5,4,1,7]
14 * Explanation: Since x1=2, x2=5, x3=1, y1=3, y2=4, y3=7 then the answer is [2,3,5,4,1,7].
15 *
16 *
17 * Example 2:
18 *
19 *
20 * Input: nums = [1,2,3,4,4,3,2,1], n = 4
21 * Output: [1,4,2,3,3,2,4,1]
22 *
23 *
24 * Example 3:
25 *
26 *
27 * Input: nums = [1,1,2,2], n = 2
28 * Output: [1,2,1,2]
29 *
30 *
31 *
32 * Constraints:
33 *
34 *
35 * 1 <= n <= 500
36 * nums.length == 2n
37 * 1 <= nums[i] <= 10^3
38 *
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/shuffle-the-array/
43// discuss: https://leetcode.com/problems/shuffle-the-array/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48 pub fn shuffle(nums: Vec<i32>, n: i32) -> Vec<i32> {
49 vec![]
50 }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58
59 #[test]
60 fn test_1470() {
61 }
62}
63
Back
© 2025 bowen.ge All Rights Reserved.