Skip to content

Commit 6eee306

Browse files
authored
Create 19.py
1 parent 7717d18 commit 6eee306

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

101-500/19.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution:
2+
# @return a ListNode
3+
def removeNthFromEnd(self, head, n):
4+
if n==0 or head==None:
5+
return None
6+
7+
head1 = ListNode(0)
8+
head1.next = head
9+
head = head1
10+
11+
p = head
12+
q = head
13+
14+
for i in xrange(0,n+1):
15+
if q!=None:
16+
q=q.next
17+
else:
18+
return None
19+
20+
while q:
21+
p=p.next
22+
q=q.next
23+
24+
p.next = p.next.next
25+
26+
return head.next

0 commit comments

Comments
 (0)