题目:
删除链表中等于给定值 val 的所有节点。
示例:
输入: 1->2->6->3->4->5->6, val = 6 输出: 1->2->3->4->5
python代码:
class Solution(object):
def removeElements(self, head, val):
if head == None:
return None
head.next = self.removeElements(head.next, val)
return head if head.val != val else head.next
心得:递归代码量少,容易理解。
本文介绍了一种使用递归方法删除链表中所有等于给定值节点的算法实现,并给出了具体的Python代码示例。
1363

被折叠的 条评论
为什么被折叠?



