Created
October 3, 2017 14:48
-
-
Save reuke/5cfb56f95f89bfbe74ccdb0805f96961 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 class Kata | |
{ | |
public static int getLoopSize(LoopDetector.Node startNode) | |
{ | |
LoopDetector.Node prev = null; | |
LoopDetector.Node curr = startNode; | |
LoopDetector.Node temp = null; | |
int n1 = 0; | |
int n2 = 0; | |
do | |
{ | |
temp = curr; | |
curr = curr.next; | |
temp.next = prev; | |
prev = temp; | |
n1++; | |
} while (curr != null); | |
curr = startNode; | |
do | |
{ | |
temp = curr; | |
curr = curr.next; | |
temp.next = null; | |
n2++; | |
} while (curr.next != null); | |
return 2 * n2 - n1 + 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment