add new code with O(1), mine is O(m+n)