324. Wiggle Sort II Medium

@problem@discussion
#Array#Divide and Conquer#Sorting#Quickselect



1/**
2 * [324] Wiggle Sort II
3 *
4 * Given an integer array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]....
5 * You may assume the input array always has a valid answer.
6 *  
7 * Example 1:
8 * 
9 * Input: nums = [1,5,1,1,6,4]
10 * Output: [1,6,1,5,1,4]
11 * Explanation: [1,4,1,5,1,6] is also accepted.
12 * 
13 * Example 2:
14 * 
15 * Input: nums = [1,3,2,2,3,1]
16 * Output: [2,3,1,3,1,2]
17 * 
18 *  
19 * Constraints:
20 * 
21 * 	1 <= nums.length <= 5 * 10^4
22 * 	0 <= nums[i] <= 5000
23 * 	It is guaranteed that there will be an answer for the given input nums.
24 * 
25 *  
26 * Follow Up: Can you do it in O(n) time and/or in-place with O(1) extra space?
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/wiggle-sort-ii/
31// discuss: https://leetcode.com/problems/wiggle-sort-ii/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36    pub fn wiggle_sort(nums: &mut Vec<i32>) {
37        
38    }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_324() {
49    }
50}
51


Back
© 2025 bowen.ge All Rights Reserved.