
思路:用列表保存链表,然后分情况讨论。
class Solution:
def removeNthFromEnd(self, head, n: int):
node_list=[head]
while head.next:
head=head.next
node_list.append(head)
remove_loc=len(node_list)-n
#要移除的位置
if len(node_list)==1:
return None
if remove_loc==0:
return node_list[0].next
if remove_loc==len(node_list)-1:
node_list[-2].next=None
return node_list[0]
else:
node_list[remove_loc-1].next=node_list[remove_loc].next
return node_list[0]









![java八股文面试[多线程]——Synchronized优化手段:锁膨胀、锁消除、锁粗化和自适应自旋锁](https://img-blog.csdnimg.cn/img_convert/faeba682ad534b409ee0c0548f6f1f78.png)









