Last active
August 29, 2015 14:06
-
-
Save wendal/fc38e906ed83564475cc 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 static void main(String[] args) { | |
int count = 0; | |
int[] array = new int[]{0, 12, 56, 58, 100, 134, 180, 200}; // 添加头尾 | |
for (int i = 0; i < array.length; i++) { | |
for (int j = i + 1; j < array.length; j++) { | |
if (array[j] - array[i] > 50) { | |
if (i + 1 == j) { | |
System.out.println("-1"); // 跳不过去了 | |
System.out.println("BAD At " + array[i] + " TO " + array[j]); | |
return; | |
} else { | |
System.out.println("JUMP At " + array[i] + " TO " + array[j-1]); | |
i = j - 1 -1; // 因为外循环还会加1 | |
count++; | |
break; | |
} | |
} | |
} | |
} | |
System.out.println(count + 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment