Leetcode Problem 905. Sort Array By Parity
905. Sort Array By Parity
AI Mock Interview
Leetcode Solutions
Approach: In-Place Partition
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Initialize two pointers
i
to 0 and
j
to
nums.length - 1
.
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]
.
Return the modified array
nums
.
Approach: Two Pass
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...