We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
感谢您的代码,很简洁,对我准备面试非常受用!
但是我发现merge_sort的终止条件应该为if len(lst) <= 1 而不是if not lst,否则程序会无限递归。
if len(lst) <= 1
if not lst
def merge_sort(lst): if len(lst) <= 1: return lst mid = len(lst) // 2 left = merge_sort(lst[:mid]) right = merge_sort(lst[mid:]) return merge(left, right) def merge(left, right): l, r, res = 0, 0, [] while l < len(left) and r < len(right): if left[l] < right[r]: res.append(left[l]) l += 1 else: res.append(right[r]) r += 1 return res + left[l:] + right[r:]
The text was updated successfully, but these errors were encountered:
没毛病!感谢!你要不直接提个pull request吧
Sorry, something went wrong.
提交才发现原来是另一个repo,闹笑话了哈哈
No branches or pull requests
感谢您的代码,很简洁,对我准备面试非常受用!
但是我发现merge_sort的终止条件应该为
if len(lst) <= 1
而不是if not lst
,否则程序会无限递归。The text was updated successfully, but these errors were encountered: