237. Delete Node in a Linked List
2016-05-03 21:27
363 查看
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.
在一个单链表中写一个函数删除一个节点(除了尾节点)
这道题很简单,只是为什么不能删除尾节点呢?加个IF语句不就好了么?
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 ; node->val = node->next->val; node->next = node->next->next; } };
这道题很简单,只是为什么不能删除尾节点呢?加个IF语句不就好了么?
相关文章推荐
- Nodejs学习item 1 -- 入门手上
- 通过ffi在nodejs中调用动态链接库(.so文件)
- 美团酒店Node全栈开发实践
- Node.js知识分类
- Leetcode题解14 237. Delete Node in a Linked List
- nodejs php go语言了解
- Zookeeper的节点znode
- 如何升级nodejs版本
- Node和Element的区别
- GetJsonNodeValue , GetJsonNodeValueFromFirstArrayItem 取JSON节点的值
- [笔记] Node-Link可视化图中移动Node后自动布局调整算法
- Debian上安装Node.js和npm
- LeetCode 24. Swap Nodes in Pairs
- 《深入浅出Node.js》学习笔记——(一)Node简介
- 【LeetCode】LeetCode——第19题:Remove Nth Node From End of List
- Node.js其他模块
- 让nodeJS支持ES6的词法----babel的安装和使用
- nodejs的一些日常操作
- 菜鸟学习nodejs--Socket.IO二(聊天服务器)
- Nodejs调试环境搭建