From db860cd2d9e3ef8a4202008927f4e61181f01990 Mon Sep 17 00:00:00 2001 From: gbabyX Date: Tue, 16 Nov 2021 14:46:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E5=AD=A6=E9=9D=A2=E8=AF=95=E9=81=87?= =?UTF-8?q?=E5=88=B0=E4=B8=AA=E5=8F=8D=E8=BD=AC=E9=93=BE=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...15\350\275\254\351\223\276\350\241\250.go" | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 "206.\345\217\215\350\275\254\351\223\276\350\241\250.go" diff --git "a/206.\345\217\215\350\275\254\351\223\276\350\241\250.go" "b/206.\345\217\215\350\275\254\351\223\276\350\241\250.go" new file mode 100644 index 0000000..6c3dd53 --- /dev/null +++ "b/206.\345\217\215\350\275\254\351\223\276\350\241\250.go" @@ -0,0 +1,29 @@ +/* + * @lc app=leetcode.cn id=206 lang=golang + * + * [206] 反转链表 + */ + +// @lc code=start +/** + * Definition for singly-linked list. + * type ListNode struct { + * Val int + * Next *ListNode + * } + */ +func reverseList(head *ListNode) *ListNode { + node := head + var last *ListNode + var ret *ListNode + for node != nil { + nxt := node.Next + node.Next = last + last = node + node = nxt + } + return last +} + +// @lc code=end +