输入一个链 : 1 -> 3 -> 5 -> 6 -> 8
输入 k = 2
返回 6 这个节点
python(2.7)
def getNode(head, k):
if(head==None or k==0): #避免控制指针
return None; node = head
listNum = 1 while(node.next != None):
listNum += 1
node = node.next if(k>listNum):
return None count = listNum - k node2 = head
for i in range(count):
node2 = node2.next return node2