DEV Community

schudy
schudy

Posted on

LeetCode 283

I use two pointers. P2 starts from index 1, while P1 starts from 0. One is for iteration and search non-zeros, the other one is for zero to exchange with the other one.

If P1 is not zero, go to the next, if P1 find a zero, P2 will exchange value with it if P2 is not zero. After exchange, P1 will go to the next one.
Alt Text

Top comments (0)