添加新题目
This commit is contained in:
25
链表/反转链表/main.go
Normal file
25
链表/反转链表/main.go
Normal file
@@ -0,0 +1,25 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user