python 链表中倒数第k个结点

题目描述

输入一个链表,输出该链表

# -*- 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
        L=[]
        while head:
            L.append(head)
            head=head.next
        if k>len(L) or k<1:
            return None
        return L[-k]
 

中倒数第k个结点。

猜你喜欢

转载自blog.csdn.net/qq_42707449/article/details/81106165