添加Go语言题解

This commit is contained in:
zouxinyao
2021-07-28 02:26:32 +08:00
parent 7eb8b4a9fd
commit 575b7612f0
52 changed files with 1679 additions and 104 deletions

View File

@@ -194,3 +194,32 @@ class Solution {
}
}
```
Go Code:
```go
func deleteDuplicates(head *ListNode) *ListNode {
// 新建一个头结点,他的下一个节点才是开始
root := &ListNode{
Next: head,
}
pre, cur := root, head
for cur != nil && cur.Next != nil {
if cur.Val == cur.Next.Val {
// 相等的话cur就一直向后移动
for cur != nil && cur.Next != nil && cur.Val == cur.Next.Val {
cur = cur.Next
}
// 循环后移动到了最后一个相同的节点。
cur = cur.Next
pre.Next = cur
} else {
cur = cur.Next
pre = pre.Next
}
}
return root.Next
}
```