mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
添加203.移除链表元素JavaScript版本
This commit is contained in:
@ -201,6 +201,28 @@ Python:
|
|||||||
|
|
||||||
Go:
|
Go:
|
||||||
|
|
||||||
|
javaScript:
|
||||||
|
|
||||||
|
```js
|
||||||
|
/**
|
||||||
|
* @param {ListNode} head
|
||||||
|
* @param {number} val
|
||||||
|
* @return {ListNode}
|
||||||
|
*/
|
||||||
|
var removeElements = function(head, val) {
|
||||||
|
const ret = new ListNode(0, head);
|
||||||
|
let cur = ret;
|
||||||
|
while(cur.next) {
|
||||||
|
if(cur.next.val === val) {
|
||||||
|
cur.next = cur.next.next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
cur = cur.next;
|
||||||
|
}
|
||||||
|
return ret.next;
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user