-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJuly20_2020.java
More file actions
37 lines (29 loc) · 816 Bytes
/
Copy pathJuly20_2020.java
File metadata and controls
37 lines (29 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Remove element from linked list - Ezee pizyy
class Solution {
public ListNode removeElements(ListNode head, int val) {
if(head == null){
return head;
}
ListNode prev;
ListNode cur = head;
while(cur.next != null) {
if(cur.next.val == val) {
ListNode temp = cur.next;
cur.next = cur.next.next;
temp = null;
}
// if(cur.next != null) {
// break;
// }
else {
cur = cur.next;
}
}
if(head.val == val){
ListNode temp = head;
head = head.next;
temp.next = null;
}
return head;
}
}