203:
简单题,但是熟悉一下python的类的编写,思维从C语言转换过来
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def removeElements(self, head: Optional[ListNode], val: int) -> Optional[ListNode]:
cur_head=ListNode(next=head)
current=cur_head
while current.next:
if current.next.val==val:
current.next=current.next.next
else:
current=current.next
return cur_head.next
707、206
都是链表算法的基础题目,但也位后续算法打下了基础,之前考研和复试都有不错的基础,这次再使用python的语法敲一遍,也算熟练了python语言
764

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



