题目描述
输入一个链表,输出该链表中倒数第k个结点。
python solution:
# -*- coding:utf-8 -*-
class ListNode:
def __init__(self, x):
self.val = x
self.next = None
class Solution:
def FindKthToTail(self, head, k):
if head is None or k<1:
return None
work = head
while k>1 and work.next is not None:
k -= 1
work = work.next
if k>1:
return None
while work.next is not None:
work = work.next
head = head.next
return head
转载于:https://www.cnblogs.com/bernieloveslife/p/10423226.html
原文链接:https://blog.csdn.net/weixin_30342827/article/details/99161975
本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。
还没有人抢沙发呢~