序列交换
序列交换
http://www.nowcoder.com/questionTerminal/2d2d27effda849968aaab26f37b83c52
def solve(nums): if len(nums) == 0: return [] odd = 0 # 数组中偶数的个数 for i in range(len(nums)): if nums[i] % 2 == 0: odd += 1 if odd == 0 or odd == len(nums): # 数组全为偶数或者全为奇数 return nums # 不能变换位置 else: return sorted(nums) # 进行排序即可 n = int(input()) nums = list(map(int,input().split())) res = solve(nums) for i in range(n): print(res[i],end = ' ')