给定一个整数数组,返回一个数组。该返回数组中第i个数字为,原数组中第i个位置的数字至少往右走多少步才能遇到比它大的数字。如果遇不到或者已经处于最右的位置,则置为-1。
给定一个整数数组,返回一个数组。该返回数组中第i个数字为,原数组中第i个位置的数字至少往右走多少步才能遇到比它大的数字。如果遇不到或者已经处于最右的位置,则置为-1。
输入为多行,第一行为一个整数N,1≤N≤106
接下来一共有N行,每一行为一个整数M,0≤M≤232-1
输出 N 行,每行一个数字表示转换之后的数组
5 91 10 3 22 40
-1 2 1 1 -1
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
int[] list = new int[n];
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (arr[j] > arr[i]) {
list[i] = j - i;
break;
}
list[i] = -1;
}
}
list[n - 1] = -1;
for (int i : list) {
System.out.println(i);
}
}
}