题解 | #输出单向链表中倒数第k个结点#
输出单向链表中倒数第k个结点
http://www.nowcoder.com/practice/54404a78aec1435a81150f15f899417d
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int count=sc.nextInt(); Node pre=null; Node head=null; for(int i=0;i<count;i++){ int cur=sc.nextInt(); Node curnode=new Node(cur); head=curnode; curnode.next=pre; pre=curnode; } int k=sc.nextInt(); Node point=head; for(int i=1;i<k;i++){ point=point.next; } System.out.println(point.getValue()); } } } class Node{ int value; Node next; public Node(int k){ this.value=k; } public int getValue(){ return this.value; } } // 注意节点顺序