LeetCode-237:Delete Node in a Linked List (Python)
来源:互联网 发布:天谕萌女萝莉数据 编辑:程序博客网 时间:2024/05/16 06:20
问题如下:
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.
解决思路如下:
Eg.a->b->c->d->e->....->z->NULL Now suppose we wan't to delete node 'c',we can't directly do b->d and free(c) as we have access only to the node to be deleted,i.e.,'c'.But we can access d via c, so we copy d's info into c's info and make c point e, in short, c is now the same as d and so we delete d and get the desired result.
代码实现:class Solution(object): def deleteNode(self, node): """ :type node: ListNode :rtype: void Do not return anything, modify node in-place instead. """ if node == None: return; node.val = node.next.val node.next = node.next.next
0 0
- LeetCode-237:Delete Node in a Linked List (Python)
- [leetcode: Python]237. Delete Node in a Linked List
- leetcode: Delete Node in a Linked List
- LeetCode Delete Node in a Linked List
- 【leetcode】Delete Node in a Linked List
- Leetcode: Delete Node in a Linked List
- [LeetCode]Delete Node in a Linked List
- 【leetcode】Delete Node in a Linked List
- Leetcode Delete Node in a Linked List
- LeetCode || Delete Node in a Linked List
- [LeetCode] Delete Node in a Linked List
- LeetCode-Delete Node in a Linked List
- 【leetCode】Delete Node In A Linked List
- [leetcode] Delete Node in a Linked List
- [LeetCode]Delete Node in a Linked List
- [leetcode]Delete Node in a Linked List
- Leetcode: Delete Node in a Linked List
- LeetCode Delete Node in a Linked List
- JavaScript语言精粹之函数篇(二)
- Android PullToRefresh——ListView使用详解
- tomcat安装和启动
- LeetCode *** 299. Bulls and Cows
- memset实例(一)
- LeetCode-237:Delete Node in a Linked List (Python)
- ubuntu下Android开发环境搭建
- EventBus StickyEvent(粘性事件) 的应用场景! 不需要手动注销事件总线
- Android 初探Retrofit2.0.1(最新版)
- springMVC mybatis mysql 配置 事务不起作用的原因
- HttpServletRequest和HttpServletResponse的常用方法
- 深入浅出RxJava三--响应式的好处
- 下载原版Windows/Office
- javaWeb学习记录:数据库:事务