题目描述
blablabla
样例
blablabla
算法1
$O(n^2)$
blablabla
时间复杂度分析:blablabla
Python 代码
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def findKthToTail(self, pListHead, k):
"""
:type pListHead: ListNode
:type k: int
:rtype: ListNode
"""
if not pListHead:
return None
root = pListHead
res = [root]
while root.next:
root = root.next
res.append(root)
if k > len(res):
return None
return res[-k]