one pass, O(1) space
todo: binary search
use a flag
String use equals not == to judge equivalence