Sort by Parity
Return a new list with all the even numbers of nums first, then all the odd numbers. Within the evens, and within the odds, keep the order they had in nums.
Example 1
nums [3,1,2,4]
returns [2,4,3,1]
Evens 2, 4 first, then odds 3, 1.
Constraints
1 <= len(nums) <= 50-100 <= nums[i] <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Arrays problems
- Trend SignsBeginner
- Alternate the SignsEasy
- Drop the Lowest ScoresEasy
- Fair CutsEasy
- Final Tank LevelEasy
- Find Closest Number to ZeroEasy
- Find Disappeared NumbersEasy
- Find Pivot IndexEasy