We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 1260aa5 + c9ddb34 commit ec4ebd8Copy full SHA for ec4ebd8
kotlin/739-Daily-Temperatures.kt
@@ -0,0 +1,18 @@
1
+import java.util.*
2
+
3
+class Solution {
4
+ fun dailyTemperatures(temperatures: IntArray): IntArray {
5
+ if (temperatures.size == 1) return intArrayOf(0)
6
+ val stack = Stack<Int>()
7
+ val resultantArray = IntArray(temperatures.size)
8
+ var poppedElement: Int
9
+ for (i in 0..temperatures.lastIndex) {
10
+ while (stack.isNotEmpty() && temperatures[stack.peek()] < temperatures[i]) {
11
+ poppedElement = stack.pop()
12
+ resultantArray[poppedElement] = i - poppedElement
13
+ }
14
+ stack.push(i)
15
16
+ return resultantArray
17
18
+}
0 commit comments