-
Notifications
You must be signed in to change notification settings - Fork 0
/
JZ18.py
37 lines (34 loc) · 1017 Bytes
/
JZ18.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class ListNode:
def __init__(self, x):
self.val = x
self.next = None
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param head ListNode类
# @param val int整型
# @return ListNode类
#
class Solution:
def deleteNode(self, head: ListNode, val: int) -> ListNode:
if head is None:
return None
elif head.val == val:
return head.next
node = head
while node.next is not None:
if node.next.val == val:
node.next = node.next.next
break
node = node.next
return head
# RecursionError: maximum recursion depth exceeded in comparison
# class Solution:
# def deleteNode(self, head: ListNode, val: int) -> ListNode:
# if head is None:
# return None
# if head.val == val:
# return head.next
# head.next = self.deleteNode(head.next, val)
# return head