diff --git a/swift/daily-temperatures.swift b/swift/daily-temperatures.swift new file mode 100644 index 0000000..319a656 --- /dev/null +++ b/swift/daily-temperatures.swift @@ -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 + } +}