You are viewing a single comment's thread. Return to all comments →
This passed using Python 3. I had to add an alias to the list.append function to get it to work.
list.append
def merge(a1, a2): swaps, i, j, result, m, n = 0, 0, 0, [], len(a1), len(a2) ra = result.append while i < m and j < n: if a1[i] <= a2[j]: ra(a1[i]) i += 1 else: ra(a2[j]) j += 1 swaps += m - i result += a1[i:] result += a2[j:] return swaps, result def msort(arr): n = len(arr) mid = n // 2 if n > 1: left_swaps, left_result = msort(arr[:mid]) right_swaps, right_result = msort(arr[mid:]) m_swaps, result = merge(left_result, right_result) return m_swaps + left_swaps + right_swaps, result return 0, arr
Seems like cookies are disabled on this browser, please enable them to open this website
Merge Sort: Counting Inversions
You are viewing a single comment's thread. Return to all comments →
This passed using Python 3. I had to add an alias to the
list.append
function to get it to work.