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
}

  

  

posted @ 2022-04-24 15:40  SoutherLea  阅读(23)  评论(0编辑  收藏  举报