237. Delete Node in a Linked List

网友投稿 226 2022-09-17

237. Delete Node in a Linked List

Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.

Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, the linked list should become 1 -> 2 -> 4 after calling your function.

/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */public class Solution public void deleteNode(ListNode node) { node.val = node.next.val; node.next = node.next.next; }}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:复盘视频号话题打榜:一场短视频的社交传播商业价值实验!
下一篇:557. Reverse Words in a String III
相关文章

 发表评论

暂时没有评论,来抢沙发吧~