classSolution:defexchange(self,nums: List[int]) -> List[int]: n =len(nums) odd, even =0,0while odd < n:if nums[odd]%2==1: nums[odd], nums[even]= nums[even], nums[odd] even +=1 odd +=1return nums
classSolution:defexchange(self,nums: List[int]) -> List[int]: i, j =0,len(nums)-1while i < j:while i < j and nums[i]&1==1: i +=1while i < j and nums[j]&1==0: j -=1 nums[i], nums[j]= nums[j], nums[i]return nums