[LeetCode] Delete Node in a Linked List
2015-09-30 00:23
776 查看
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;
* struct ListNode *next;
* };
*/
void deleteNode(struct ListNode* node) {
node->val=node->next->val;
node->next=node->next->next;
}
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;
* struct ListNode *next;
* };
*/
void deleteNode(struct ListNode* node) {
node->val=node->next->val;
node->next=node->next->next;
}
相关文章推荐
- node.js下LDAP查询实例分享
- 10个常见的Node.js面试题
- NodeJs学习笔记01-你好Node
- LeetCode——Populating Next Right Pointers in Each Node
- node.js下LDAP查询实践
- 第7课 nodejs请求响应
- 第五课 nodejs 路由实现并处理请求作出响应
- 2015第40周二Node学习
- 使用node.js进行API自动化回归测试
- 让node跑得更快的建议
- Sublime Text3 简单开发nodejs
- 开始学习Nodejs的API参考文档<2>
- nodejs 版本更新问题(v0.8.14 -> v4.1.1)
- Node.js实践第一天
- Nodejs学习<2>
- nodejs模块xml2js解析xml的坑
- nodejs模块xml2js解析xml的坑
- Nodejs学习<1>
- 更新包地址安装新版node.js
- Populating Next Right Pointers in Each Node 解答