AC

O(2n) time
O(1) space