Skip to main content

🟢 剑指 Offer 21. 调整数组顺序使奇数位于偶数前面

LeetCode 提示

题目难度 简单

原题链接 🔗 leetcode

题解 1.py#

class Solution:    def exchange(self, nums: List[int]) -> List[int]:        di = 0        for idx in range(len(nums)):            n = nums[idx]            if n%2:                nums[di], nums[idx] = nums[idx], nums[di]                di += 1            else:                pass        return nums