Skip to content

Commit

Permalink
Time: 0 ms (100%), Space: 4.2 MB (10.58%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
hovanhoa committed Oct 25, 2024
1 parent 3ccb2c2 commit 89725f3
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions 0206-reverse-linked-list/0206-reverse-linked-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,15 @@
* }
*/
func reverseList(head *ListNode) *ListNode {
if head == nil {
return head
}

cur, tail := head, head.Next
for tail != nil {
cur = tail
tail = tail.Next
cur.Next = head
if head.Next == cur {
head.Next = nil
}
var prev *ListNode
cur := head

head = cur
for cur != nil {
nxt := cur.Next
cur.Next = prev
prev = cur
cur = nxt
}

return cur
return prev
}

0 comments on commit 89725f3

Please sign in to comment.