one pass! time O(n) space O(1)