Skip to content

Latest commit

 

History

History
60 lines (40 loc) · 1.11 KB

0083.remove-duplicates-from-sorted-list.md

File metadata and controls

60 lines (40 loc) · 1.11 KB

0083.Remove-Duplicates-from-Sorted-List

Description

Given a sorted linked list, delete all duplicates such that each element appear only once.

Example 1:

Input: 1->1->2
Output: 1->2

Example 2:

Input: 1->1->2->3->3
Output: 1->2->3

Tags: Linked List

题意

给你两个二进制串,求其和的二进制串。

题解

思路1

按照小学算数那么来做,用 carry 表示进位,从后往前算,依次往前,每算出一位就插入到最前面即可,直到把两个二进制串都遍历完即可。

```go func deleteDuplicates(head ListNode) ListNode { if head == nil || head.Next == nil { return head }

curr := head

for curr.Next != nil {
    if curr.Next.Val == curr.Val {
        curr.Next = curr.Next.Next
    } else {
        curr = curr.Next
    }
}

return head

}

### 思路2
> 思路2
```go

结语

如果你同我一样热爱数据结构、算法、LeetCode,可以关注我 GitHub 上的 LeetCode 题解:awesome-golang-algorithm