922. Sort Array By Parity II Easy

@problem@discussion
#Array#Two Pointers#Sorting



1/**
2 * [922] Sort Array By Parity II
3 *
4 * Given an array of integers nums, half of the integers in nums are odd, and the other half are even.
5 * Sort the array so that whenever nums[i] is odd, i is odd, and whenever nums[i] is even, i is even.
6 * Return any answer array that satisfies this condition.
7 *  
8 * Example 1:
9 * 
10 * Input: nums = [4,2,5,7]
11 * Output: [4,5,2,7]
12 * Explanation: [4,7,2,5], [2,5,4,7], [2,7,4,5] would also have been accepted.
13 * 
14 * Example 2:
15 * 
16 * Input: nums = [2,3]
17 * Output: [2,3]
18 * 
19 *  
20 * Constraints:
21 * 
22 * 	2 <= nums.length <= 2 * 10^4
23 * 	nums.length is even.
24 * 	Half of the integers in nums are even.
25 * 	0 <= nums[i] <= 1000
26 * 
27 *  
28 * Follow Up: Could you solve it in-place?
29 * 
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/sort-array-by-parity-ii/
34// discuss: https://leetcode.com/problems/sort-array-by-parity-ii/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39    pub fn sort_array_by_parity_ii(nums: Vec<i32>) -> Vec<i32> {
40        vec![]
41    }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn test_922() {
52    }
53}
54


Back
© 2025 bowen.ge All Rights Reserved.