题目描述
输入一个链表,输出该链表中倒数第k个结点。
1 /* 2 public class ListNode { 3 int val; 4 ListNode next = null; 5 6 ListNode(int val) { 7 this.val = val; 8 } 9 }*/ 10 public class Solution { 11 public ListNode FindKthToTail(ListNode head,int k) { 12 ListNode h = head; 13 while(k!=0) { 14 if(h==null)return null; 15 h=h.next; 16 k--; 17 } 18 while(h!=null){ 19 head=head.next; 20 h=h.next; 21 } 22 return head; 23 } 24 }