2899. Last Visited Integers

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 2899

class Solution:
    def lastVisitedIntegers(self, words: List[str]) -> List[int]:
        nums = []
        res = []
        k = 0
        for w in words:
            if w == "prev":
                k += 1
                i = len(nums) - k
                res.append(-1 if i < 0 else nums[i])
            else:
                k = 0
                nums.append(int(w))
        return res