这个题目用链表就过于复杂了。可以先用字符串读入输入的序列,然后转化成数组,用快慢指针解决问题即可。

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
            while(in.hasNextInt()){
            int len = in.nextInt();
            StringBuilder s = new StringBuilder();
            for(int i=0;i<len;++i){
                s.append(in.nextInt()+" ");
            }
            int k = in.nextInt();
            if(k<1||k>len) System.out.println(0);
            else {
                String str = s.toString();
                String []ss = str.split(" ");
                int count = 0;
                for(int i=0;i<ss.length;++i){
                    if(i>=k){
                        ++count;
                    }
                }
                System.out.println(ss[count]);
                } 
        }
    }
}