swift: add «739. Daily Temperatures»

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2024-06-02 11:12:08 +02:00
parent 81e5186b71
commit 97fecfe614
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -0,0 +1,17 @@
class Solution {
func dailyTemperatures(_ temperatures: [Int]) -> [Int] {
var result = [Int](repeating: 0, count: temperatures.count)
var st: [Int] = []
for (i, t) in temperatures.enumerated() {
while !st.isEmpty && temperatures[st.last!] < t {
result[st.last!] = i - st.last!
st.removeLast()
}
st.append(i)
}
return result
}
}