add O(1) space solution
add some comment to help understand the sol