提交代码

class Solution {
	public ListNode removeElements(ListNode head, int val) {
		ListNode dummy = new ListNode(0);
		dummy.next = head;
		ListNode p1 = dummy, p2 = dummy.next;

		while (p2!= null) {
			while ( p2!= null && p2.val != val) {
				p1.next=p2;
				p1=p2;
				p2=p2.next;
			}
			if(p2!=null&&p2.val==val) {
				while(p2!=null&&p2.val==val)
					p2=p2.next;
				p1.next=p2;
			}
		}
		return dummy.next;
	}
}

运行结果

【leetcode】203(Easy)Remove Linked List Elements

相关文章:

  • 2021-09-01
  • 2021-12-23
  • 2022-01-04
  • 2022-02-26
  • 2021-07-05
猜你喜欢
  • 2021-05-27
  • 2021-07-02
  • 2021-11-20
  • 2021-07-21
  • 2021-10-26
  • 2021-06-11
  • 2022-01-31
相关资源
相似解决方案