Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LongestPlateau {
- public static void main(String[] args) {
- args = new String[] {"5", "5", "5", "5", "3", "8", "8", "8", "1"};
- // args = new String[] {"1", "2", "2", "2", "2", "5", "5", "5", "3"};
- // args = new String[] { "1", "2", "3", "4" };
- int N = args.length;
- int[] a = new int[N];
- for (int i = 0; i < N; i++) {
- a[i] = Integer.parseInt(args[i]);
- }
- boolean longestIsAtFront = true;
- int currentLength = 0;
- int longestLength = 0;
- int plateauStart = 0;
- for (int i = 0; i < N; i++) {
- if (a[plateauStart] == a[i]) {
- currentLength++;
- } else if (a[plateauStart] < a[i]) {
- if (longestLength < currentLength) {
- longestLength = currentLength;
- longestIsAtFront = false;
- }
- currentLength = 0;
- if (!longestIsAtFront) {
- plateauStart = i;
- }
- } else {
- if (longestLength < currentLength) {
- longestLength = currentLength;
- }
- currentLength = 0;
- }
- System.out.println(plateauStart + " " + longestLength);
- }
- if (longestLength < currentLength) {
- longestLength = currentLength;
- }
- System.out.println(plateauStart + " " + longestLength);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement