237. Delete Node in a Linked List
2016-05-17 11:04
239 查看
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
the linked list should become
【难度】Easy
【思路】直接将下一个节点覆盖掉要删除的节点
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.
【难度】Easy
【思路】直接将下一个节点覆盖掉要删除的节点
/** * 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; } };
相关文章推荐
- Nodejs开源项目里怎么样写测试、CI和代码测试覆盖率
- 详解DataNode的容量监控页面参数
- 理解“索引节点”inode
- 24. Swap Nodes in Pairs [easy]
- nodejs:grunt使用合并压缩的基本使用
- nodejs的一些核心概念
- nodejs 小工具——supervisor
- 25. Reverse Nodes in k-Group
- nodejs MODEL层 封装(二)
- 玩转DOM遍历——用NodeIterator实现getElementById,getElementsByTagName方法
- Node异步执行&回调函数
- Node.js可以做什么? Node.js究竟是什么?
- nodejs实践-代码组织
- nodejs npm常用命令
- Ubuntu安装node
- node.js安装
- nodejs+mysql+css项目1
- node修改全局环境路径 与 全局后出现sh:exe command not found
- Node.js与Express4安装与配置
- Node.js初入门