@Override public String toString() { return"ListNode [val=" + val + "]"; } }
publicstatic ListNode getLastNode(ListNode head, int n) { if (head == null || n <= 0) { returnnull; }
ListNode left = head; ListNode right = head;
for (int i = 1; i < n; i++) { right = right.next; if (right == null) { returnnull; } } while (right.next != null) { left = left.next; right = right.next; } return left; }