剑指offer_数组_调整数组顺序使奇数位于偶数前面
程序员文章站
2022-07-10 12:20:02
...
数组_调整数组顺序使奇数位于偶数前面
思路:可参考https://blog.csdn.net/qq_33487726/article/details/92790140
https://blog.csdn.net/qq_20141867/article/details/81105004
# -*- coding:utf-8 -*-
class Solution:
def reOrderArray(self, array):
# write code here
num1 = 0
num0 = 0
length = len(array)
for e in array:
if e%2 == 1:
num1 += 1
res = [None]*length
for e in array:
if e % 2 == 1:
res[num0] = e
num0 += 1
else:
res[num1] = e
num1 += 1
return res
上一篇: Python3学习(七):模块
下一篇: 剑指offer之:51数组中的逆序对
推荐阅读