一、題目描述
輸入一個(gè)鏈表,輸出該鏈表中倒數(shù)第k個(gè)結(jié)點(diǎn)。
二、代碼實(shí)現(xiàn)
# -*- coding:utf-8 -*-
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def FindKthToTail(self, head, k):
# write code here
if head == None: return None
p = head
q = head
while k-1:
if p.next == None: return None
p = p.next
k = k-1
while p.next:
p = p.next
q = q.next
return q