Files
Hot-100-Algorithm/链表/反转链表/main.go

26 lines
325 B
Go
Raw Normal View History

2025-08-23 23:09:54 +08:00
package main
type ListNode struct {
Val int
Next *ListNode
}
func main() {
}
func reverseList(head *ListNode) *ListNode {
pre := (*ListNode)(nil)
res := (*ListNode)(nil)
for head != nil {
next := head.Next
head.Next = pre
pre = head
if next == nil {
res = head
break
}
head = next
}
return res
}