Brute force: scan ahead
Time O(n²) Space O(1)For each day, look ahead until a warmer day.
class Solution {
public int[] dailyTemperatures(int[] t) {
int[] ans = new int[t.length];
for (int i = 0; i < t.length; i++)
for (int j = i + 1; j < t.length; j++)
if (t[j] > t[i]) { ans[i] = j - i; break; }
return ans;
}
}Verdict: Too slow for 10⁵ days on falling temperatures.