答案,注意,一种是递归,另一种是迭代,那么巧妙利用双指针: 迭代: public static LinkedListNode nthToLast(LinkedListNode head, int n) { LinkedListNode p1 = head; LinkedListNode p2 = head; if (n <= 0) return null; // Move p2 n nodes into the list. Keep n1 in the same position. for (i…
输入一个链表,输出该链表中倒数第K个结点 public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; } public class Solution { public ListNode FindKthToTail(ListNode head,int k) { ListNode p = head; ListNode pre = head; int a =k; int count…