Leetcode Problem 905. Sort Array By Parity

905. Sort Array By Parity

Leetcode Solutions

Approach: In-Place Partition

  1. Initialize two pointers i to 0 and j to nums.length - 1.
  2. While i < j: a. Increment i until nums[i] is odd. b. Decrement j until nums[j] is even. c. If i < j, swap nums[i] and nums[j].
  3. Return the modified array nums.
UML Thumbnail

Approach: Two Pass

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...