1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-10 00:09:06 +01:00
LeetCode/swift/daily-temperatures.swift
Matej Focko 97fecfe614
swift: add «739. Daily Temperatures»
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-06-02 11:12:08 +02:00

17 lines
447 B
Swift

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
}
}