Leetcode 206. 反转链表
206. 反转链表 - 力扣(LeetCode) (leetcode-cn.com)

思路:
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/
func reverseList(head *ListNode) *ListNode {
curHead:=head
preHead:=new(ListNode)
preHead=nil
for curHead!=nil{
tempHead:=curHead.Next
curHead.Next=preHead
preHead=curHead
curHead=tempHead
}
return preHead
}

浙公网安备 33010602011771号