Exemplo n.º 1
0
  public static ListNode removeElements(ListNode head, int val) {
    while (head != null && head.val == val) head = head.next;
    ListNode p = head;
    while (head != null && head.next != null) {
      while (head.next != null && head.next.val == val) {
        head.next = head.next.next;
      }

      head = head.next;
    }
    return p;
  }
Exemplo n.º 2
0
 public static void main(String a[]) {
   ListNode node = new ListNode(1);
   node.print();
   node = removeElements(node, 1);
   node.print();
 }