3467. Transform Array by Parity
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 89% Topics: Array, Sorting, Counting
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
# array
class Solution(object):
def transformArray(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
cnt = 0
for x in nums:
if x%2:
continue
nums[cnt] = 0
cnt += 1
for i in xrange(cnt, len(nums)):
nums[i] = 1
return nums
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions