标签:int || 输出 sub while val his ++ scribe
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 12 13 public ListNode FindKthToTail(ListNode head,int k) { 14 if(head==null||k<=0){ 15 return null; 16 } 17 ListNode pre=head; 18 ListNode last=head; 19 for(int i=1;i<k;i++){ 20 if(pre.next!=null){ 21 pre=pre.next; 22 }else{ 23 return null; 24 } 25 } 26 while(pre.next!=null){ 27 pre = pre.next; 28 last=last.next; 29 } 30 return last; 31 } 32 }
标签:int || 输出 sub while val his ++ scribe
原文地址:https://www.cnblogs.com/Octopus-22/p/9432679.html