Created
July 19, 2021 16:45
-
-
Save wohhie/1ac402bffd63fae5f20a5b29c732c847 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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