File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -37,10 +37,19 @@ def merge(left: list, right: list) -> list:
3737 :return: Merged result
3838 """
3939 result = []
40- while left and right :
41- result .append (left .pop (0 ) if left [0 ] <= right [0 ] else right .pop (0 ))
42- result .extend (left )
43- result .extend (right )
40+ left_index = right_index = 0
41+ length_left , length_right = len (left ) , len (right )
42+
43+ while (left_index < length_left ) and (right_index < length_right ):
44+ if left [left_index ] < right [right_index ]:
45+ result .append (left [left_index ])
46+ left_index += 1
47+ else :
48+ result .append (right [right_index ])
49+ right_index += 1
50+
51+ result .extend (left [left_index : ])
52+ result .extend (right [right_index : ])
4453 return result
4554
4655 if len (collection ) <= 1 :
You can’t perform that action at this time.
0 commit comments