![JAR search and dependency download from the Maven repository](/logo.png)
g2801_2900.s2899_last_visited_integers.Solution.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-kotlin Show documentation
Show all versions of leetcode-in-kotlin Show documentation
Kotlin-based LeetCode algorithm problem solutions, regularly updated
package g2801_2900.s2899_last_visited_integers
// #Easy #Array #String #Simulation #2023_12_21_Time_209_ms_(72.73%)_Space_37.7_MB_(72.73%)
class Solution {
fun lastVisitedIntegers(words: List): List {
val prevEle: MutableList = ArrayList()
val res: MutableList = ArrayList()
var count = 0
for (i in words.indices) {
if (words[i] != "prev") {
count = 0
prevEle.add(words[i])
continue
}
if (count >= prevEle.size) {
res.add(-1)
} else {
res.add(prevEle[prevEle.size - count - 1].toInt())
}
count++
}
return res
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy