链接:https://leetcode-cn.com/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/
思路:
快排partition
代码:
class Solution { public: vector<int> exchange(vector<int>& nums) { int l = 0, r = nums.size() - 1; while (l <= r) { while (l <= r && nums[l] % 2 == 1) l++; while (l <= r && nums[r] % 2 == 0) r--; if (l < r) swap(nums[l], nums[r]); } return nums; } };