标签:tco poi point href sel integer turn not pytho
题目描述:
分割一个整数数组,使得奇数在前偶数在后。
给定 [1, 2, 3, 4]
,返回 [1, 3, 2, 4]
。
在原数组中完成,不使用额外空间。
题目分析:
在原数组中完成,不使用额外空间。
源码:
class Solution: # @param nums: a list of integers # @return: nothing def partitionArray(self, nums): # write your code here if nums is None: return None i = 0 j = len(nums) - 1 while i<j: if nums[i]%2 == 0: nums[i],nums[j] = nums[j],nums[i] j = j - 1 else: i = i + 1
LintCode Python 简单级题目 373.奇偶分割数组
标签:tco poi point href sel integer turn not pytho
原文地址:http://www.cnblogs.com/bozhou/p/6956270.html