输出单向链表中倒数第k个结点
输出单向链表中倒数第k个结点
http://www.nowcoder.com/questionTerminal/54404a78aec1435a81150f15f899417d
不需要实现链表,当成数组就行
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]); } } } }