Advertisement
Mishakis

LongestIncreasingSequence

Nov 30th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1.  
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         int N = scanner.nextInt();
  11.  
  12.         int[] array = new int[N];
  13.  
  14.         for (int i = 0; i < array.length; i++) {
  15.             array[i] = scanner.nextInt();
  16.             scanner.nextLine();
  17.         }
  18.  
  19.         int currentLength = 1;
  20.         int maxLength = 0;
  21.  
  22.         for (int i = 1; i < array.length; i++) {
  23.             if (array[i - 1] < array[i ]) {
  24.                 currentLength++;
  25.                 maxLength= Math.max(maxLength, currentLength);
  26.             } else {
  27.                 maxLength= Math.max(maxLength, currentLength);
  28.                 currentLength = 1;
  29.             }
  30.         }
  31.         if(currentLength > maxLength){
  32.             maxLength = currentLength;
  33.         }
  34.  
  35.         System.out.println(maxLength);
  36.  
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement