package main
import"fmt"funcexchange(nums []int)[]int{iflen(nums)==0{return[]int{}}var i =0var j =len(nums)-1for; i < j;{for; i < j && nums[i]%2==1;{
i++}for; i < j && nums[j]%2==0;{
j--}if i < j {
tmp := nums[i]
nums[i]= nums[j]
nums[j]= tmp
}}return nums
}funcmain(){
nums :=[]int{1,2,3,4}
fmt.Println(exchange(nums))}
Python
from typing import List
classSolution:defexchange(self, nums: List[int])-> List[int]:ifnot nums:return[]
i, j =0,len(nums)-1while i < j:while i < j and nums[i]%2==1: i +=1while i < j and nums[j]%2==0: j -=1if i < j:
nums[i], nums[j]= nums[j], nums[i]return nums
if __name__ =="__main__":
nums =[1,2,3,4]
solution = Solution()print(solution.exchange(nums))