You are given an integer array actions
, where each number is the ID of a training project.
The goal is to rearrange the array so that all odd numbers come before all even numbers.
Return the adjusted array.
Example 1
Input: [1,2,3,4,5]
Output: [1,3,5,2,4]
Constraints
0 <= actions.length <= 50000
0 <= actions[i] <= 10000
We want all odds on the left side and all evens on the right side.
Use two pointers:
left
starts at the beginning.right
starts at the end.Steps:
left
is even and right
is odd → swap them.left
is odd → move left
forward.right
is even → move right
backward.left >= right
.