Skip to content
New issue

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

书本上的4.3练习这样改会更加严谨一点 #11

Closed
chichungceng opened this issue Dec 16, 2018 · 1 comment
Closed

书本上的4.3练习这样改会更加严谨一点 #11

chichungceng opened this issue Dec 16, 2018 · 1 comment

Comments

@chichungceng
Copy link

原代码:
def max(arr):
if len(arr) == 2:
return arr[0] if arr[0]>arr[1] else arr[1]
else:
sub_max = max(arr[1:])
return arr[0] if arr[0]>sub_max else sub_max

修改后:
def max(arr):
if len(arr) == 1:
return arr[0]
elif len(arr) == 2:
return arr[0] if arr[0]>arr[1] else arr[1]
else:
sub_max = max(arr[1:])
return arr[0] if arr[0]>sub_max else sub_max

@zhanwen
Copy link
Owner

zhanwen commented Dec 17, 2018

书上的更易于理解哦

@zhanwen zhanwen closed this as completed Dec 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants