We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d41475a commit f3e55d5Copy full SHA for f3e55d5
5.mergeSort.md
@@ -70,4 +70,30 @@ function merge(left, right)
70
71
return result;
72
}
73
-```
+```
74
+
75
+## 4. Python 代码实现
76
77
+```python
78
+def mergeSort(arr):
79
+ import math
80
+ if(len(arr)<2):
81
+ return arr
82
+ middle = math.floor(len(arr)/2)
83
+ left = arr[0:middle]
84
+ right = arr[middle:]
85
+ return merge(mergeSort(left), mergeSort(right))
86
87
+def merge(left,right):
88
+ result = []
89
+ while left and right:
90
+ if left[0] <= right[0]:
91
+ result.append(left.pop(0));
92
+ else:
93
+ result.append(right.pop(0));
94
+ while left:
95
96
+ while right:
97
98
+ return result
99
0 commit comments