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.
1 parent cc17920 commit 828a71eCopy full SHA for 828a71e
1 file changed
solution/2800-2899/2899.Last Visited Integers/Solution.py
@@ -1,14 +1,13 @@
1
class Solution:
2
- def lastVisitedIntegers(self, words: List[str]) -> List[int]:
3
- nums = []
+ def lastVisitedIntegers(self, nums: List[int]) -> List[int]:
+ seen = []
4
ans = []
5
k = 0
6
- for w in words:
7
- if w == "prev":
+ for x in nums:
+ if x == -1:
8
k += 1
9
- i = len(nums) - k
10
- ans.append(-1 if i < 0 else nums[i])
+ ans.append(-1 if k > len(seen) else seen[-k])
11
else:
12
13
- nums.append(int(w))
+ seen.append(x)
14
return ans
0 commit comments