public class ListNode {// 结点的值int val;// 下一个结点ListNode next;// 节点的构造函数(无参)public ListNode() {}// 节点的构造函数(有一个参数)public ListNode(int val) {this.val = val;}// 节点的构造函数(有两个参数)public ListNode(int val, ListNode next) {this.val = val;this.next = next;}
}
给你一个链表的头节点 head 和一个整数 val ,请你删除链表中所有满足 Node.val == val 的节点,并返回 新的头节点 。

 * Definition for singly-linked list.* public class ListNode {*     int val;*     ListNode next;*     ListNode() {}*     ListNode(int val) { this.val = val; }*     ListNode(int val, ListNode next) { this.val = val; this.next = next; }* }*/
class Solution {public ListNode removeElements(ListNode head, int val) {while(head !=null && head.val==val){head=head.next;}if(head==null){return null;}ListNode pre = head;ListNode cur = head.next;while(cur!=null){if(cur.val==val){pre.next=cur.next;}else{pre = cur;}cur = cur.next;}return head;}
}

/*** Definition for singly-linked list.* public class ListNode {*     int val;*     ListNode next;*     ListNode() {}*     ListNode(int val) { this.val = val; }*     ListNode(int val, ListNode next) { this.val = val; this.next = next; }* }*/
class Solution {public ListNode removeElements(ListNode head, int val) {if(head==null){return head;}//增加头结点ListNode dummy = new ListNode(-1,head);ListNode pre = dummy;ListNode cur = head;while(cur!=null){if(cur.val==val){pre.next=cur.next;}else{pre=cur;}cur=cur.next;}return dummy.next;}
}

有一个单链表的 head,我们想删除它其中的一个节点 node。
 给你一个需要删除的节点 node 。你将 无法访问 第一个节点 head。
 链表的所有值都是 唯一的,并且保证给定的节点 node 不是链表中的最后一个节点。
 删除给定的节点。
注意,删除节点并不是指从内存中删除它。这里的意思是:
给定节点的值不应该存在于链表中。
链表中的节点数应该减少 1。
node 前面的所有值顺序相同。
node 后面的所有值顺序相同。

 
 乍一看题目不知道在说什么
 


看完大家的吐槽之后 大概明白要干什么了,那就把把自己变成儿子 再把儿子干掉
/*** Definition for singly-linked list.* public class ListNode {*     int val;*     ListNode next;*     ListNode(int x) { val = x; }* }*/
class Solution {public void deleteNode(ListNode node) {node.val=node.next.val;node.next=node.next.next;}
}
