LeetCode:Delete Node in a Linked List
2015-10-22 10:33
381 查看
问题描述:
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
代码:
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 -> 4and you are given the third node with value
3,
the linked list should become
1 -> 2 -> 4after 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) { ListNode *p = node -> next; node -> val = p -> val; node -> next = p -> next; free (p); } };
相关文章推荐
- Webpack 实现 Node.js 代码热替换
- leetcode: Swap Nodes in Pairs
- LeetCode Populating Next Right Pointers in Each Node & Populating Next Right Pointers in Each Node I
- Node.js巧妙实现Web应用代码热更新
- Event Sourcing - ENode(一)
- [LeetCode] Delete Node in a Linked List
- Node.js巧妙实现Web应用代码热更新
- Webpack 实现 Node.js 代码热替换
- 浅谈node.js中async异步编程
- 第 三 十 七 天:增 加 inode 和 挂 载 ios 镜 像
- Swap Nodes in Pairs
- nodejs字符与字节之间的转换
- 如何提高NodeJS程序的稳定性
- ListNode
- XML——SelectSingleNode 获取有命名空间的节点的值
- NodeJS学习_1
- 【Glassfish】GlassFish中Domain、DAS、cluster、 instance以及node agent之间的关系
- nodejs图片转换字节保存
- nodejs实战express笔记之实现用户和文章页面
- Nodejs 模块