题解 | #输出单向链表中倒数第k个结点#先不要着急批评
输出单向链表中倒数第k个结点
https://www.nowcoder.com/practice/54404a78aec1435a81150f15f899417d
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { //获取字符串 int num = scanner.nextInt(); List<Integer> list = new ArrayList<>(); for (int i = 0; i < num; i++) { list.add(scanner.nextInt()); } int k = scanner.nextInt(); if (k != 0 && k <= list.size()) { System.out.println(list.get(list.size() -k)); } } scanner.close(); } }