2899. Last Visited Integers
Содержание
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