MCPcopy Create free account
hub / github.com/careercup/ctci / nthToLastR3Helper

Method nthToLastR3Helper

java/Chapter 2/Question2_2/Question.java:30–42  ·  view source on GitHub ↗
(LinkedListNode head, int k)

Source from the content-addressed store, hash-verified

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);

Callers 1

nthToLastR3Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected