LeetCode 237 : Delete Node in a Linked List
2015-07-27 13:54
543 查看
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
从链表中,删除指定的节点,但又没有给出前指针,所以先交换当前节点和下一节点的值,然后删除下一节点即可。代码如下:
Supposed the linked list is
1 -> 2 -> 3 -> 4and you are given the third node with value
3, the linked list should become
1 -> 2 -> 4after calling your function.
从链表中,删除指定的节点,但又没有给出前指针,所以先交换当前节点和下一节点的值,然后删除下一节点即可。代码如下:
void deleteNode(ListNode* node) { if (!node || !node->next) return; node->val = node->next->val; node->next = node->next->next; }
相关文章推荐
- Node.js爬虫数据抓取 -- 问题总结
- Leetcode 24 Swap Nodes in Pairs
- LeetCode 24 Swap Nodes in Pairs
- node.js简单的页面输出
- LeetCode-Delete Node in a Linked List
- jQuery静态方法noop,camelCase,nodeName,trim使用和源码分析
- LeetCode Swap Nodes in Pairs 交换结点对(单链表)
- 带你入门带你飞Ⅰ 使用Mocha + Chai + Sinon单元测试Node.js
- Koa (koajs) 基于 Node.js 平台的下一代 web 开发框架
- 通过Cloudera Manager为datanode增加数据目录
- [LeetCode]Swap Nodes in Pairs
- 【LeetCode】237 & 203 - Delete Node in a Linked List & Remove Linked List Elements
- [LeetCode]Populating Next Right Pointers in Each Node
- LeetCode-Remove Nth Node From End of List
- Reverse Nodes in k-Group
- leetcode[24]:Swap Nodes in Pairs
- javascrip中parentNode和offsetParent之间的区别
- 【Leetcode】Delete Node in a LinkedList
- [Leetcode 25] Reverse Nodes in k-Group
- leetcode[117]:Populating Next Right Pointers in Each Node II