【剑指offer】Q14:调整数组顺序使奇数位于偶数前面
def isOdd(n):
return n & 1
def Reorder(data, cf = isOdd):
odd = 0
even = len( data ) - 1
while True:
while not isOdd( data[ even ]) : even -= 1
while isOdd( data[ odd ]) : odd += 1
if odd >= even: break
data[ even ], data[ odd ] = data[ odd ], data[ even ]
posted on 2019-04-08 09:02 xfgnongmin 阅读(89) 评论(0) 编辑 收藏 举报