【leetcode】Delete Node in a Linked List
2015-07-19 19:57
579 查看
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 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; else { node->val=node->next->val; node->next=node->next->next; } } };
相关文章推荐
- Node:Trie数(字典树)
- secondarynamenode无法启动
- node.js乱码
- 多次格式化namenode,datanode无法启动的解决办法
- #25 Reverse Nodes in k-Group
- Swap Nodes in Pairs
- node模块的载入及机制
- node及npm安装过程中的win环境变量设置
- Node:KMP之next数组
- [CareerCup] 2.3 Delete Node in a Linked List 删除链表的节点
- node-inspector使用方法
- 开始刷leetcode day71:Delete Node in a Linked List
- leetcode_237题——Delete Node in a Linked List(链表)
- Node.js笔记
- Leetcode NO.237 Delete Node in a Linked List
- [Leetcode 237, Easy] Delete Node in a Linked List
- #24 Swap Nodes in Pairs
- 19 Remove Nth Node From End of List
- 关于nodejs面试
- LeetCode 237 Delete Node in a Linked List