# Question

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 ListNode.
* public class ListNode {
*     int val;
*     ListNode next;
*     ListNode(int val) {
*         this.val = val;
*         this.next = null;
*     }
* }
*/
public class Solution {
/**
* @param node: the node in the list should be deleted
* @return: nothing
*/
public void deleteNode(ListNode node) {
node.val = node.next.val;
node.next = node.next.next;
}
}```

0 条评论

## 相关文章

1572

3685

### Bessie的好牌（队列）- POJ 3629

Bessie is playing a card game with her N-1 (2 ≤ N ≤ 100) cow friends using a dec...

1233

2206

5599

2556

1875

### 野生前端的数据结构基础练习（6）——集合

3.为Set类增加一个higher(element)方法，该方法返回比传入元素大的元素中最小的一个，并写一段代码来测试该功能。

1063

### C#集合类型大盘点

C#集体类型（ Collections in C#） 　　集合是.NET FCL(Framework Class Library)中很重要的一部分，也是我们开发...

2927

34110