merge method of o(1) space complexity

still have some problems