Skip to content

Commit

Permalink
同学面试遇到个反转链表
Browse files Browse the repository at this point in the history
  • Loading branch information
walkerxiong committed Nov 16, 2021
1 parent 42bfde7 commit db860cd
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions 206.反转链表.go
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit db860cd

Please sign in to comment.