class ListNode:
def __init__(self,x):
self.val = x
self.next = None
def getiNodex(self, head,n,i):
'''
head:链表头结点
n:链表长度
i:返回第i个节点node i
'''
if i < 0 or i > n-1:
raise Exception('超出索引')
p = self.head
for cur in range(i):
p = p.next
return p
网友评论