pre, nex = 0, 0 while pre < len(nums): if nums[pre] % 2 == 1: nums[pre], nums[nex] = nums[nex], nums[pre] nex += 1 pre += 1 return nums ''' l, r = 0, len(nums) - 1 while l < r: while l < r and nums[l] % 2 == 1: l += 1 while l < r and nums[r] % 2 == 0: r -= 1 nums[l], nums[r] = nums[r], nums[l] return nums l, r = 0, len(nums) - 1 while l < r: if nums[l] % 2 == 1: l += 1 continue elif nums[r] % 2 == 0: r -= 1 continue nums[l], nums[r] = nums[r], nums[l] return nums