← 返回 google 的题目列表Rearrange Array to Place Even Numbers Before Odd Numbers
类型:online_judge
google
Given an integer array nums, rearrange its elements such that all even numbers appear before all odd numbers.
Input Description:
A list of integers nums with length at most $10^5$.
Each integer has an absolute value up to $10^4$.
Output Description:
Return a list of integers where all even numbers are placed before all odd numbers.
Example:
Input: [3,1,2,4]
Output: [2,4,3,1] or [4,2,1,3]
Constraints: The algorithm should run in O(n) time with O(1) space complexity.
Example
Input
[3,1,2,4]