Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. private static int[] longestPlateau(int[] ints){
  2. int miscellenous_Start = 0, miscelleneous_Length = 1,
  3. longestPlateau_Length = 0, longestPlateau_Start = 1;
  4.  
  5. if (ints.length == 0){
  6. return new int[]{0,0,0};
  7. }else if (ints.length == 1){
  8. return new int[]{ints[0], 0 , ints.length};
  9. }else {
  10. miscelleneous_Length++;
  11. }
  12.  
  13. for (int i = 1; i < ints.length + 1; i++){
  14. if ((i == ints.length)|| (ints[i] < ints[i - 1])){
  15. if ((miscelleneous_Length > longestPlateau_Length)) {
  16. longestPlateau_Length = miscelleneous_Length;
  17. longestPlateau_Start = miscellenous_Start;
  18. }
  19. }else if ((ints[i] == ints[i - 1])
  20. && (ints[miscellenous_Start] == ints[i])){
  21. miscelleneous_Length++;
  22. }else {
  23. miscellenous_Start = i;
  24. miscelleneous_Length = 1;
  25. }
  26. }
  27. return new int[] {ints[longestPlateau_Start],
  28. longestPlateau_Start, longestPlateau_Length};
  29. }
  30.  
  31. public static void main(String[] args) {
  32. int[] test1 = { 4, 1, 1, 6, 6, 6, 6, 1, 1}; //"[ 6 , 3 , 4 ]"
  33. int[] test2 = { 3, 3, 1, 2, 4, 2, 1, 1, 1, 1}; //"[ 3 , 0 , 2 ]"
  34. int[] test3 = { 3, 3, 1, 2, 4, 0, 1, 1, 1, 1}; //"[ 1 , 6 , 4 ]"
  35. int[] test4 = { 3, 3, 3, 4, 1, 2, 4, 4, 0, 1}; //"[ 4 , 6 , 2 ]"
  36. int[] test5 = { 7, 7, 7, 7, 9, 8, 2, 5, 5, 5, 0, 1}; //"[ 5 , 7 , 3 ]"
  37. int[] test6 = { 4 }; //"[ 4 , 0 , 1 ]"
  38. int[] test7 = { 4, 4, 4, 5, 5, 5, 6, 6}; //"[ 6 , 6 , 2 ]"
  39. int arr1[] = longestPlateau(test1);
  40. System.out.println(arr1[0] + ", " + arr1[1] + ", " + arr1[2]);
  41. int arr[] = longestPlateau(test2);
  42. System.out.println(arr[0] + ", " + arr[1] + ", " + arr[2]);
  43. int[] arr2 = longestPlateau(test3);
  44. System.out.println(arr2[0] + ", " + arr2[1] + ", " + arr2[2]);
  45. int[] arr3 = longestPlateau(test4);
  46. System.out.println(arr3[0] + ", " + arr3[1] + ", " + arr3[2]);
  47. int[] arr4 = longestPlateau(test5);
  48. System.out.println(arr4[0] + ", " + arr4[1] + ", " + arr4[2]);
  49. int[] arr5 = longestPlateau(test6);
  50. System.out.println(arr5[0] + ", " + arr5[1] + ", " + arr5[2]);
  51. int[] arr6 = longestPlateau(test7);
  52. System.out.println(arr6[0] + ", " + arr6[1] + ", " + arr6[2]);
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement