Skip to content

Commit f4a1ddb

Browse files
committed
committed from zkp
1 parent 5c78bc7 commit f4a1ddb

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution(object):
2+
def removeNthFromEnd(self, head, n):
3+
"""
4+
:type head: ListNode
5+
:type n: int
6+
:rtype: ListNode
7+
"""
8+
curnode = head
9+
s = []
10+
while curnode:
11+
s.append(id(curnode))
12+
curnode = curnode.next
13+
t = s[-n]
14+
if id(head) == t:
15+
head = head.next
16+
else:
17+
d_curnode = head
18+
while d_curnode:
19+
if id(d_curnode.next) == t:
20+
d = d_curnode.next
21+
d_curnode.next = d.next
22+
del d
23+
break
24+
d_curnode = d_curnode.next
25+
return head

0 commit comments

Comments
 (0)