Skip to content

Commit e58abd7

Browse files
authored
Merge pull request #9 from chakyam/master
Update
2 parents c3251a4 + 20b94bc commit e58abd7

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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

0 commit comments

Comments
 (0)