难度:容易
1. Description
373. 奇偶分割数组2. Solution
- python
class Solution:
"""
@param: nums: an array of integers
@return: nothing
"""
def partitionArray(self, nums):
# write your code here
n = len(nums)
if n<=1:
return nums
left = 0
right = n-1
while True:
while nums[left]%2!=0 and left<n-1: # find even num
left+=1
while nums[right]%2==0 and right>0: # find odd num
right-=1
if left<right:
nums[left],nums[right]=nums[right],nums[left]
else:
break
return nums
网友评论