Skip to content

Instantly share code, notes, and snippets.

@wendal
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wendal/fc38e906ed83564475cc to your computer and use it in GitHub Desktop.
Save wendal/fc38e906ed83564475cc to your computer and use it in GitHub Desktop.
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