Merge pull request #257 from betNevS/master

添加0203.移除链表元素 go版本
This commit is contained in:
Carl Sun
2021-05-26 09:24:38 +08:00
committed by GitHub

View File

@ -201,6 +201,29 @@ Python
Go Go
```go
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/
func removeElements(head *ListNode, val int) *ListNode {
dummyHead := &ListNode{}
dummyHead.Next = head
cur := dummyHead
for cur != nil && cur.Next != nil {
if cur.Next.Val == val {
cur.Next = cur.Next.Next
} else {
cur = cur.Next
}
}
return dummyHead.Next
}
```
javaScript: javaScript:
```js ```js