Skip to content

Commit

Permalink
Time: 0 ms (100%), Space: 4.8 MB (13.74%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
hovanhoa committed Nov 6, 2024
1 parent 0b8dc6a commit 7d3e328
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/
func deleteDuplicates(head *ListNode) *ListNode {
if head == nil {
return head
}

cur, nxt := head, head.Next
for nxt != nil {
if cur.Val != nxt.Val {
cur.Next = nxt
cur = nxt
}

nxt = nxt.Next
}

cur.Next = nxt

return head
}

0 comments on commit 7d3e328

Please sign in to comment.