Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Definition for ListNode
- * public class ListNode {
- * int val;
- * ListNode next;
- * ListNode(int x) {
- * val = x;
- * next = null;
- * }
- * }
- */
- public class Solution {
- /**
- * @param head: a ListNode
- * @param val: An integer
- * @return: a ListNode
- */
- public ListNode removeElements(ListNode head, int val) {
- ListNode dummy = new ListNode(0);
- dummy.next = head;
- ListNode p = dummy;
- while (p != null) {
- while (p.next != null && p.next.val == val) {
- p.next = p.next.next;
- }
- p = p.next;
- }
- return dummy.next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement