不需要实现链表,当成数组就行
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
int[] list = new int[n];
for(int i = 0; i < n; i++){
list[i] = sc.nextInt();
}
int k = sc.nextInt();
if(k <= 0 || k > n){
System.out.println(0);
}else{
System.out.println(list[n - k]);
}
}
}
}
京公网安备 11010502036488号