Solution Review: Partitioning of 0s, 1s and 2s
Let's look at the solution to the challenge posed in the previous lesson.
We'll cover the following...
Solution
The basic approach is to use three indices. The first is left
, the second is right
, and the third is i
that is used to traverse the array. The index on the left begins at 0
, while the index on the right begins at n-1
. When we discover a 0
in the array, we swap it with the start ...