Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit163f2e6

Browse files
authored
Create 203-remove-linked-list-elements.js
Solved remove linked linked list in JS.
1 parent3cfb9a5 commit163f2e6

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// problem link https://leetcode.com/problems/remove-linked-list-elements/
2+
// time complexity O(n).
3+
4+
varremoveElements=function(head,val){
5+
// let currunt = head;
6+
letpre=newListNode(null,head);
7+
letdummy=pre;
8+
while(head){
9+
if(head.val==val){
10+
while(head&&head.val==val){
11+
head=head.next;
12+
}
13+
pre.next=head;
14+
pre=head;
15+
if(head){
16+
temp=head;
17+
head=head.next;
18+
temp=null;
19+
}
20+
continue;
21+
}
22+
pre=pre.next;
23+
head=head.next;
24+
}
25+
26+
returndummy.next;
27+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp