题解 | #输出单向链表中倒数第k个结点#
输出单向链表中倒数第k个结点
https://www.nowcoder.com/practice/54404a78aec1435a81150f15f899417d
class ListNode: def __init__(self, key=None) -> None: self.key = key self.next = None def push(self, val): if not self.key: self.key = val else: l = ListNode(val) cur = self while cur.next: cur = cur.next cur.next = l while True: try: num = input() nodes = input().strip().split() tar = int(input().strip()) l = ListNode() for i in nodes: l.push(i) res = [] cur = l while cur: res.append(cur.key) cur = cur.next print(res[-tar]) except: break