Skip to content

Instantly share code, notes, and snippets.

@ugandapinik
Created July 19, 2021 16:45
Show Gist options
  • Save ugandapinik/1ac402bffd63fae5f20a5b29c732c847 to your computer and use it in GitHub Desktop.
Save ugandapinik/1ac402bffd63fae5f20a5b29c732c847 to your computer and use it in GitHub Desktop.
public int findNthLinkedList(Node head, int n) {
Node runner = head;
Node walker = head;
for (int i = 0; i < n; i++){
runner = runner.next;
}
if (runner == null) return head.next.data;
while (runner != null){
runner = runner.next;
walker = walker.next;
}
return walker.data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment