class Solution {
public ListNode removeElements(ListNode head, int val) {
if (head == null){
return null;
}
while(head.val == val && head != null){
ListNode delNode = head;
head = head.next;
delNode.next = null;
}
ListNode prev = head;
while (prev.next != null){
if(prev.next.val == val){
ListNode delNode = prev.next;
prev.next = delNode.next;
delNode.next = null;
}
else{
prev = prev.next;
}
}
return head;
}
public static void main(String[] args) {
ListNode head = null;
Solution s = new Solution();
String s1 = s.removeElements(head,1).toString();
System.out.println(s1);
}
}