Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.

For example, given nums = [0, 1, 0, 3, 12], after calling your function, nums should be [1, 3, 12, 0, 0].

Note: You must do this in-place without making a copy of the array. Minimize the total number of operations.

``````P0: k = i - j
``````

``````P1: 任意 0 < k,  A'(n - k) = 0
P2: 对于任意的 0 <= j <= i < n,  A'(j) = A(i) != 0
``````

``````int i, j, k
i := j := k := 0

do i < n ->
if A(i) = 0 -> // x1: 这里应满足 P0
| A(i) != 0 -> // x2: 这里应满足 P2
fi
i := i + 1; //x3: 使循环往终止方向推进
od
``````

x1: 只需要加一句 k := k+1 ，就能得到 (k + 1) = (i + 1) - j ，重新满足 P0 x2: 我们必须让 A(j + 1) := A(i + 1) 才能使 P2 重新得到满足，另外，还需要加一句 j := j + 1, 才能得到 k := (i + 1) - (j + 1), 重新满足 P0

``````do k > 0 ->
// x4: 满足 P1
k := k - 1;
od
``````

``````int i, j, k
i := j := k := 0

do i < n ->
if A(i) = 0 ->
k := k+1;
| A(i) != 0 ->
A(j + 1) := A(i + 1); j = j + 1;
fi
i := i + 1;
od

do k > 0 ->
A(n - k) := 0;
k := k - 1;
od
``````