Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 475ca1d

Browse files
committed
No203
1 parent 237c7c3 commit 475ca1d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

leetcode/LinkedList/No203.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* public class ListNode {
4+
* int val;
5+
* ListNode next;
6+
* ListNode(int x) { val = x; }
7+
* }
8+
*/
9+
class Solution {
10+
public ListNode removeElements(ListNode head, int val) {
11+
ListNode prehead = new ListNode(-1);
12+
prehead.next = head;
13+
ListNode cur = head,pre = prehead;
14+
while(cur != null){
15+
if(cur.val == val){
16+
pre.next = cur.next;
17+
}else{
18+
pre = pre.next;
19+
}
20+
cur = cur.next;
21+
}
22+
return prehead.next;
23+
}
24+
}

0 commit comments

Comments
 (0)