diff --git a/solution/237.Delete Node in a Linked List/Solution.py b/solution/237.Delete Node in a Linked List/Solution.py index e69de29bb2d1d..21a8f316ea8de 100644 --- a/solution/237.Delete Node in a Linked List/Solution.py +++ b/solution/237.Delete Node in a Linked List/Solution.py @@ -0,0 +1,16 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def deleteNode(self, node): + """ + :type node: ListNode + :rtype: void Do not return anything, modify node in-place instead. + """ + tmp=node.next + node.val=tmp.val + node.next=tmp.next + \ No newline at end of file diff --git a/solution/876.Middle of the Linked List/Solution.py b/solution/876.Middle of the Linked List/Solution.py index e69de29bb2d1d..facf3eb381253 100644 --- a/solution/876.Middle of the Linked List/Solution.py +++ b/solution/876.Middle of the Linked List/Solution.py @@ -0,0 +1,23 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def middleNode(self, head): + """ + :type head: ListNode + :rtype: ListNode + """ + if not head: + return None + if not head.next: + return head + fast=head + slow=head + while fast.next: + fast=fast.next.next + slow=slow.next + if not fast or not fast.next: + return slow \ No newline at end of file