Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- Integer[] array = {1,3,5,7,2,2,3,4,8,9};
- int startIndex = 0;
- int lenghtSequence = 1;
- int bestStartIndex = 0;
- int bestLenghtSequence = 0;
- for (int i = 1; i < array.length; i++) {
- if (array[i-1] + 1 == array[i]) {
- lenghtSequence ++;
- continue;
- }
- if (bestLenghtSequence < lenghtSequence) {
- bestLenghtSequence = lenghtSequence;
- bestStartIndex = startIndex;
- }
- lenghtSequence = 1;
- startIndex = i;
- }
- for (int i = bestStartIndex; i < bestStartIndex + bestLenghtSequence; i++) {
- System.out.print(array[i] + " ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement