v3 time O(m*n) space O(m+n) Accepted