File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
237.Delete Node in a Linked List
876.Middle of the Linked List Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Definition for singly-linked list.
2
+ # class ListNode:
3
+ # def __init__(self, x):
4
+ # self.val = x
5
+ # self.next = None
6
+
7
+ class Solution :
8
+ def deleteNode (self , node ):
9
+ """
10
+ :type node: ListNode
11
+ :rtype: void Do not return anything, modify node in-place instead.
12
+ """
13
+ tmp = node .next
14
+ node .val = tmp .val
15
+ node .next = tmp .next
16
+
Original file line number Diff line number Diff line change
1
+ # Definition for singly-linked list.
2
+ # class ListNode:
3
+ # def __init__(self, x):
4
+ # self.val = x
5
+ # self.next = None
6
+
7
+ class Solution :
8
+ def middleNode (self , head ):
9
+ """
10
+ :type head: ListNode
11
+ :rtype: ListNode
12
+ """
13
+ if not head :
14
+ return None
15
+ if not head .next :
16
+ return head
17
+ fast = head
18
+ slow = head
19
+ while fast .next :
20
+ fast = fast .next .next
21
+ slow = slow .next
22
+ if not fast or not fast .next :
23
+ return slow
You can’t perform that action at this time.
0 commit comments