标签:
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 if(head==null||k==0){ 13 return null ; 14 } 15 ListNode p = new ListNode(0) ; 16 ListNode q = new ListNode(0) ; 17 p = head ; 18 q = head ; 19 while(k>1&&p.next!=null){ 20 p=p.next ; 21 k-- ; 22 } 23 if(k>=2){ 24 return null ; 25 } 26 while(p.next !=null&&q.next!=null){ 27 p=p.next ; 28 q=q.next; 29 } 30 return q ; 31 } 32 }
标签:
原文地址:http://www.cnblogs.com/huntertoung/p/4765161.html