206. 反转链表
Me
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/
func reverseList(head *ListNode) *ListNode {
x := head
y := head
var z *ListNode
temp := head
for head != nil {
x = temp
y = temp.Next
x.Next = z
if y == nil {
break
}
temp = y
z = x
}
return x
}
作者:HodgeKou
链接:https://leetcode-cn.com/problems/reverse-linked-list/solution/206-fan-zhuan-lian-biao-ji-bai-liao-10000-de-yong-/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。