题解 | 输出单向链表中倒数第k个结点

输出单向链表中倒数第k个结点

https://www.nowcoder.com/practice/54404a78aec1435a81150f15f899417d

import sys

args = []

index = 0
temp = []
for line in sys.stdin:
    a = line.split("\n")[0]
    if index == 0:
        temp.append(int(a))
    elif index == 1:
        temp.append([int(_) for _ in a.split(" ")])
    elif index == 2:
        index = 0
        temp.append(int(a))
        args.append(temp)
        temp = []
        continue
    index += 1

for arg in args:
    #print(arg[1],len(arg[1])-arg[2])
    print(arg[1][len(arg[1])-arg[2]])

这个可以用数组来偷懒,如果要用链表,搞个双向的也行

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务