Use something like two pointer, a pointer to indicate current position, another to indicate next append position of the new array. Since do not need to actually decrease the length of vector, we just need to told the length of the vector then it will get the length of the vector.