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.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/ class Solution {
public:
void deleteNode(ListNode* node) {
if(node == NULL) return;
node->val = node->next->val;
node->next = node->next->next;
}
};

没什么好说的,下面是java版本的:

 /**
* 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;
}
}

LeetCode OJ:Delete Node in a Linked List(链表节点删除)的更多相关文章

  1. Leetcode 237 Delete Node in a Linked List 链表

    如题 删除是要注意让现在的链表等于下一个链表的值 class Solution { public: void deleteNode(ListNode* node) { ListNode *nextno ...

  2. [LeetCode] 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 th ...

  3. LeetCode 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 th ...

  4. [LeetCode] 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 th ...

  5. (easy)LeetCode 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 th ...

  6. leetcode: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 th ...

  7. Java [Leetcode 273]Delete Node in a Linked List

    题目描述: Write a function to delete a node (except the tail) in a singly linked list, given only access ...

  8. leetcode 237 Delete Node in a Linked List python

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

  9. 17.leetcode 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 th ...

  10. [Leetcode]237. Delete Node in a Linked List -David_Lin

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

随机推荐

  1. 4.1 使用STM32控制MC20拨打电话

    需要准备的硬件 MC20开发板 1个 https://item.taobao.com/item.htm?id=562661881042 GSM/GPRS天线 1根 https://item.taoba ...

  2. php mysqli扩展库之预处理操作

    分享下php使用mysqli扩展库进行预处理操作的二个例子,有意研究mysqli用法的朋友,可以参考学习下,一定会有所帮助的. 例1.使用mysqli扩展库的预处理技术 mysqli stmt 向数据 ...

  3. mysql之视图,触发器,事务等

    一.视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,可以将该结果集当做表来使用. 使用视图我们可以把查询过程中的 ...

  4. hibernate 操作 Postgresql 数据库报 operator does not exist: integer = character varying

    网上的说法如下: Java开发Postgresql 数据库兼容应用的问题,与Oracle有一些不同: Java类型映射数据库类型的不同,Oracle jdbc驱动程序处理Java String类型可正 ...

  5. android各种组件的监听器

    <一>Spinner(旋转按钮或下拉列表):设置监听器为:setOnItemSelectedListener 设置动画效果为:setOnTouchListener              ...

  6. javascript;Jquery;获取JSON对象,无刷新分页,异步加载,异步删除,实例。

    AjaxNewsList: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> < ...

  7. TCP客户端和服务器间传输数据遇到的TypeError: a bytes-like object is required, not 'str'问题

    使用python实现python核心编程3第472页和474页的TCP时间戳服务器和客户端服务器间数据传输编程时遇到TypeError: a bytes-like object is required ...

  8. window端口号被占用解决

    1. 找到占用该端口的pid netstat -ano|findstr "端口号" 2. 强制关闭该占用该端口的进程 // 关闭 taskkill -pid 刚才查的pid // ...

  9. 【leetcode刷题笔记】Sudoku Solver

    Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...

  10. https网站无法加载http路径的js和css

    在https的网站中引用http路径的js或css会导致不起作用,其形如: <script src="http://code.jquery.com/jquery-1.11.0.min. ...