Time Limit Exceeded?


  • 0
    I

    I have a O(n) C# Solution. My submission fails with Time Limit Exceeded message, yet it also states that 161 / 161 test cases passed..

    Here is my code:

    `

    public class Solution {
    public int RemoveDuplicates(int[] nums) {        
        
        if (nums.Length == 0)
        {
            return 0;
        }
        
        int i = 0;
        var done = false;
        
        while (!done)
        {
            int j = i + 1;
            
            while (j < nums.Length && nums[j] <= nums[i])
            {
                j++;
            }
            
            if (j >= nums.Length)
            {
                done = true;
            }            
            else
            {
                nums[i+1] = nums[j];
                i++;   
            }
        }
        
        return i + 1;
        
    }
    }
    

    `


Log in to reply
 

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