aboutsummaryrefslogtreecommitdiff
path: root/sort_array_parity.py
blob: 4e318fd168594f1701e4bc8b4c019c2997165f49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 905. Sort Array By Parity

"""
given an integer array 'nums', move all the even integers at the beginning of
the array followed by all the odd integers. return any array that satisfies
this condition
"""

class Solution(object):
    def sortArrayByParity(self, nums):
        left = 0
        for i in range(len(nums)):
            if nums[i] % 2 == 0:
                nums[left], nums[i] = nums[i], nums[left]
                left += 1
        return nums