private static int FindKth(ListNode head, int k) { //null check if (head == null || k < 1) return -1; int i = 1; ListNode val = head; while (head != null) { // not enough nodes if (head.next == null && i < k) return -1; else { if (i == k && head.next == null) { return val.val; } else { if (i == k) val = val.next; else i++; } head = head.next; } } return -1; }