Why the system gave different result with an unrevised code???


  • 1
    Z
    public class Solution {
        public boolean containsNearbyDuplicate(int[] nums, int k) {
            int size = nums.length;
            if(size == 0) return false;
            if(k == 0)return false;
            HashSet<Integer> set = new HashSet<Integer>();
            for(int i = 0; i < nums.length; i++){
                if(i-k-1 >= 0)set.remove(nums[i - k - 1]);
                if(set.contains(nums[i]))return true;
                set.add(nums[i]);
            }
            return false;
        }
    }
    

    I am sure my code will work. But the first time I submitted my code the system gave a Time Limit Exceeded result. After a short while, I submitted the exactly the same code, but this time system gave an Accepted result........And the code beat 75% of all results......

    What is the reason? Is the system unstable?


  • 1
    Q

    I met similar situation although I didn't have TLE problem. But the ranks are different each time. It seems they have some random test cases.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.