[Leetcode 237, Easy] Delete Node in a Linked List
2015-07-19 02:57
561 查看
Problem:
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
with value
Analysis:
Solutions:
C++:
Java:
Python:
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.
Analysis:
Solutions:
C++:
void deleteNode(ListNode* node) { if(node->next == NULL) return; node->val = node->next->val; node->next = node->next->next; }
Java:
Python:
相关文章推荐
- #24 Swap Nodes in Pairs
- 19 Remove Nth Node From End of List
- 关于nodejs面试
- LeetCode 237 Delete Node in a Linked List
- Remove Nth Node From End of List
- LeetCode: Reverse Nodes in k-Group
- Delete Node in a Linked List
- 237-e-Delete Node in a Linked List
- leetcode | Reverse Nodes in k-Group
- Node.js开发环境配置
- 学习老外用webstorm开发nodejs的技巧--代码提示DefinitelyTyped
- Node 实现 AES 加密,结果输出为“byte”。
- Delete Node in a Linked List
- Remove Nth Node From End of List
- [LeetCode]Delete Node in a Linked List
- leetcode | Swap Nodes in Pairs in a linklist
- ubuntu server 14.10 安装 nodejs
- Delete Node in a Linked List
- Node实践之二
- Windows环境下的nodejs环境开发搭建