Description
Given an array of integers temperatures representing daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. If there is no future day with warmer temperature, keep answer[i] == 0.
Examples
temperatures = [73,74,75,71,69,72,76,73][1,1,4,2,1,1,0,0]For each day, the number of days until a warmer temperature: day 0 (73°) s 1 day for 74°, day 1 (74°) s 1 day for 75°, day 2 (75°) s 4 days for 76°, day 3 (71°) s 2 days for 72°, day 4 (69°) s 1 day for 72°, day 5 (72°) s 2 days for 76°, and days 6-7 have no warmer day ahead.
temperatures = [30,40,50,60][1,1,1,0]Each day, the next day is warmer except the last.
temperatures = [80,70,65,75,85,60][4,2,1,1,0,0]For day 0 (80°), the next warmer day is day 4 (85°), a gap of 4. For day 1 (70°), day 3 (75°) is warmer, a gap of 2. Day 2 (65°) reaches 75° at day 3, gap of 1. Days with no warmer future day get 0.
Constraints
- •
1 ≤ temperatures.length ≤ 10⁵ - •
30 ≤ temperatures[i] ≤ 100