一、反向
通用步骤:
- Initialize two pointer i = 0, j = array.length - 1
- while i <= j:
- Decide what you should do based on the value of array[i] and array[j]
- Move at least one pointer forward in its direction
二、同向
通用步骤:
- Initialize two pointers i and j, usually both equal to 0
- while i < array.length:
- if we need array[i], then we keep it by assigning array[i] = array[j], and move i forward, make it ready at the next position
- otherwise skip it. We do not need to move i since its spot is not fulfilled