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
def reverse(head): reverse_head = None current = head while current: reverse_head,reverse_head.next,current = current,reverse_head,current.next
为什么 reverse_head = current reverse_head.next = reverse_head current = current.next 这样会出错
The text was updated successfully, but these errors were encountered:
因为第一句reverse_head变成了current,这样第二句就成了reverse_head.next = current
Sorry, something went wrong.
因为很多其他语言不像python一样可以连续赋值,那么代码应该如何写,求赐教
赐教不敢当。 你只需要用一个tmp变量保存之前的reverse_head就行了,因为你的目的是 reverse_head = current reverse_head.next = 之前的reverse_head
python这里其实相当于在等号右边帮你创建了一个临时的tuple,然后这个临时的变量再依次赋给左边那些。
No branches or pull requests
def reverse(head):
reverse_head = None
current = head
while current:
reverse_head,reverse_head.next,current = current,reverse_head,current.next
为什么
reverse_head = current
reverse_head.next = reverse_head
current = current.next
这样会出错
The text was updated successfully, but these errors were encountered: