p0 to 0, p2 to n - 1, and curr to 0.curr is less than or equal to p2:
nums[curr] is 0, swap nums[curr] with nums[p0] and increment both p0 and curr.nums[curr] is 2, swap nums[curr] with nums[p2] and decrement p2.nums[curr] is 1, increment curr.curr is greater than p2.