> For the complete documentation index, see [llms.txt](https://chen-zhao-fei.gitbook.io/shu-ju-jie-gou-yu-suan-fa/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://chen-zhao-fei.gitbook.io/shu-ju-jie-gou-yu-suan-fa/lian-biao/1.-fan-zhuan-lian-biao.md).

# 1.反转链表

```
/**
 * Definition for singly-linked list.
 * type ListNode struct {
 *     Val int
 *     Next *ListNode
 * }
 */
func reverseList(head *ListNode) *ListNode {
    var pre *ListNode
    for head !=nil{
        next:=head.Next
        head.Next=pre
        pre=head
        head=next
    }
    return pre
}
```
