剑指offer-链表中倒数第k个结点(python)

# -*- 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
        d=[]
        if not head:
            return None
        count=0
        while head:
            d.append(head)
            head=head.next
            count+=1
        if k>count or k<1:
            return
        return d[-k]
发布了69 篇原创文章 · 获赞 46 · 访问量 5276

猜你喜欢

转载自blog.csdn.net/qq_42738654/article/details/104224699