class Solution:
def exchange(self, nums: List[int]) -> List[int]:
n=len(nums)
l=0;r=n-1
while l<r:
while l<r and nums[l]&1: l+=1 # l<r 很重要
while l<r and nums[r]&1==0: r-=1 # l<r 很重要
if l<r: nums[l],nums[r]=nums[r],nums[l] # l<r 很重要
return nums
04-29
04-29
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交