Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- public class Neighbour {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int size = Integer.parseInt(scanner.nextLine());
- String[] input = scanner.nextLine().split(" ");
- List<Integer> result = new ArrayList<>();
- for(int i = 0; i < size;i++){
- result.add(Integer.parseInt(input[i]));
- }
- int index = -1;
- for(int i = 1; i < result.size() -1 ;i++){
- if( result.get(i - 1) < result.get(i) && result.get(i) > result.get(i + 1)){
- index = i;
- break;
- }/*else{
- index = result.indexOf(result.get(i + 1));
- break;
- }*/
- }
- System.out.println(index);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement