题解 | 左侧严格小于计数
左侧严格小于计数
https://www.nowcoder.com/practice/c5922c6cdd1445749bd42f586c422435
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int a[] = new int[n];
for(int i = 0; i < n; i++){
a[i] = in.nextInt();
}
int b[] = new int[n];
for(int i = 0; i < n; i++){
int count = 0; //这里的count不能放在for外面,否则会变成前向累加
for(int j = 0; j < i; j++){
if(a[j] < a[i]){
count++;
}
}
b[i] = count;
}
for(int i = 0; i < n; i++){
System.out.print(b[i] + " ");
}
}
}

查看10道真题和解析