简述 给定非负整数数组,该数组中奇数的个数和偶数的个数相同。重新排列数组,使元素的奇偶性和元素的索引的奇偶性一致。sort-array-by-parity-ii 英文 中文 收获 1.初始化一个固定长度的数组 代码 12345678910111213141516171819 class : def sortArrayByParityII(self, A): """ :type A: List[int] :rtype: List[int] """ lst = [None] * len(A) evenIndex,oddIndex = 0,1 for x in A: if x % 2 == 0: lst[evenIndex] = x evenIndex += 2 else: lst[oddIndex] = x oddIndex += 2 return lst 赞微海报分享
近期评论