MCPcopy Create free account
hub / github.com/BeeBombshell/Python-DSA / Solution

Class Solution

Sort-all/merge.py:1–17  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Solution:
2 def sortArray(self, N: List[int]) -> List[int]:
3 def mergesort(A):
4 LA = len(A)
5 if LA == 1: return A
6 LH, RH = mergesort(A[:LA//2]), mergesort(A[LA//2:])
7 return merge(LH,RH)
8
9 def merge(LH, RH):
10 LLH, LRH = len(LH), len(RH)
11 S, i, j = [], 0, 0
12 while i < LLH and j < LRH:
13 if LH[i] <= RH[j]: i, _ = i + 1, S.append(LH[i])
14 else: j, _ = j + 1, S.append(RH[j])
15 return S + (RH[j:] if i == LLH else LH[i:])
16
17 return mergesort(N)
18
19

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected