面试题21
输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有奇数位于数组的前半部分,所有偶数位于数组的后半部分。
提示:
1 <= nums.length <= 50000
1 <= nums[i] <= 10000
Solutions
two pointers
Another approach is stacking odd numbers at the beginning of array, however, there are too much assignment operations in this approach.
Last updated
Was this helpful?