剑指offer python版 调整数组顺序使奇数位于偶数前面

def aa(nums):
    if not nums:
        return False
    left,right=0,len(nums)-1
    mid=(left+right)/2
    while left<mid<right:
        while not bb(nums[left]):
            left +=1
        while  bb(nums[right]):
            right -=1
        nums[left],nums[right]=nums[right],nums[left]
        left +=1
        right -=1
    
    return nums
    
    
    
def bb(n):
    if n&1==0:
        return True
        
    
print(aa([1,2,3,4,5,6,7]))
            

 

posted @ 2018-10-25 16:10  findtruth123  阅读(518)  评论(0编辑  收藏  举报