mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-09 15:59:06 +01:00
swift: add «739. Daily Temperatures»
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
81e5186b71
commit
97fecfe614
1 changed files with 17 additions and 0 deletions
17
swift/daily-temperatures.swift
Normal file
17
swift/daily-temperatures.swift
Normal 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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue