public int[] dailyTemperatures(int[] temperatures) {
int len = temperatures.length;
LinkedList<Integer>[] table = new LinkedList[101];
for(int i = 30; i < 101; i++) table[i] = new LinkedList<>();
for(int i = 0; i < len; i++) {
int num = temperatures[i];
table[num].add(i);
}
int[] ans = new int[len];
for(int i = 0; i < len; i++) {
int thisNum = temperatures[i];
int dis = len;
for(int j = thisNum+1; j < 101; j++) {
List<Integer> list =table[j];
while (list.size() > 0 ) {
int firstIndex = list.get(0);
if(firstIndex < i) list.remove(0);
else {
dis = Math.min(dis, firstIndex-i);
break;
}
}
}
ans[i] = dis==len?0:dis;
}
System.out.println(Arrays.toString(ans));
return ans;
}