按照字面意思暴力解法的 运行会超时 结果是30分
代码如下:
import java.util.HashMap;
import java.util.Map;
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 < arr.length; i++) {
arr[i] = sc.nextInt();
}
for (int i = 0; i < arr.length; i++) {
while(method(arr,arr[i],0,i)) {
arr[i] ++;
}
System.out.print(arr[i] + " ");
}
}
/**
* 此方法用于判断数组arr里面有没有数num
* @author ouqi
* @date 2022-03-26 17:43:39
* @param arr
* @param num
*/
private static boolean method(int[] arr,int num,int start,int end) {
Map<Integer,Integer> map = new HashMap<>();
for (int i = start; i < end; i++) {
map.put(arr[i], 1);
}
for (Map.Entry<Integer,Integer> entry : map.entrySet()) {
if(entry.getKey() == num) {
return true;
}
}
return false;
}
}