(LinkedListNode head, int k)
| 28 | } |
| 29 | |
| 30 | public static Result nthToLastR3Helper(LinkedListNode head, int k) { |
| 31 | if (head == null) { |
| 32 | return new Result(null, 0); |
| 33 | } |
| 34 | Result res = nthToLastR3Helper(head.next, k); |
| 35 | if (res.node == null) { |
| 36 | res.count++; |
| 37 | if (res.count == k) { |
| 38 | res.node = head; |
| 39 | } |
| 40 | } |
| 41 | return res; |
| 42 | } |
| 43 | |
| 44 | public static LinkedListNode nthToLastR3(LinkedListNode head, int k) { |
| 45 | Result res = nthToLastR3Helper(head, k); |