Skip to content

Two Pointers

Two pointers method is really an easy and effective technique for searching in an array or list.

There are two kinds of usage:

  1. two pointers runs in same direction, one slower-runner and the other faster-runner, an example is to remove duplicates from a sorted array;
  2. two pointers runs in different direction, one from the begining while the other starts from the end, the example can be to reverse the characters in a string.

Problems: