Last active
November 4, 2017 17:24
-
-
Save balamark/56665755c627af00f4f64f1bee10ee4c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 periodLength(int[] heaps) { | |
ArrayList<Integer> slow = new ArrayList<Integer>(); | |
for (int i=0; i<heaps.length; i++) slow.add(heaps[i]); | |
Collections.sort(slow); | |
ArrayList<Integer> fast = slow; | |
while (true) { | |
slow = step(slow); | |
fast = step(fast); | |
fast = step(fast); | |
if (slow.equals(fast)) { | |
int period = 0; | |
while (true) { | |
slow = step(slow); | |
period++; | |
if (slow.equals(fast)) return period; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment