华为机试HJ51输出单向链表中倒数第k个结点
题目:

想法:
因为要用链表,且要找到倒数第k个结点,针对输入序列倒叙进行构建链表并找到对应的元素输出。注意因为有多个输入,要能接受多次调用
class Node(object):
    def __init__(self, val=0):
        self.val = val
        self.next = None
        
        
while True:
    try:
        head = Node()
        count, num_list, k = int(input()), list(map(int, input().split())), int(input())
        while k:
            head.next = Node(num_list.pop())
            head = head.next
            k -= 1
        print(head.val)
    except EOFError:
        break
上述代码中先构建链表结点类,使用while循环使得代码可以接受多个输入。
![[Godot3.3.3] – 人物死亡动画 part-2](https://i-blog.csdnimg.cn/direct/36a50a547dba46d9be44585bc8f789bd.png)


















