Java | 1ms | Beats 100%
\n# Code\njava []\nclass Solution {\n    public List<Integer> lastVisitedIntegers(int[] nums) {\n        int lastSeen = -1;\n        List<Integer> result = new 
\n# Code\n```java []\nclass Solution {\n    public List<Integer> lastVisitedIntegers(int[] nums) {\n        int lastSeen = -1;\n        List<Integer> result = new ArrayList<>();\n        for(int i=0;i<nums.length;i++) {\n            if(nums[i]>=0) lastSeen = i;\n            else {\n                if(lastSeen < 0) result.add(-1);\n                else {\n                    result.add(nums[lastSeen]);\n                    lastSeen--;\n                    while(lastSeen>=0 && nums[lastSeen]==-1) {\n                        lastSeen--;\n                    }\n                }\n            }\n        }\n        return result;\n    }\n}\n```
['Java']