c# solution, Memory Limit Exceeded ,need help


  • 0
    L
       public string RemoveKdigits(string num, int k) 
        {
            if(num.Length == k) return "0";
            while(k-->0)
            {
                if(num[1] == '0')
                {
                        int firstNotZero = 1;
                        while(firstNotZero < num.Length  && num[firstNotZero] == '0') firstNotZero ++;
                        num=num.Remove(0,firstNotZero);
                } 
                else
                {
                        int startIndex = 0;
                        while(startIndex < num.Length - 1  && num[startIndex] <= num[startIndex + 1]) startIndex ++;
                        num=num.Remove(startIndex,1);
                }
            }
            if(num == "") return "0";
            return num;
        }
    

  • 1
    L

    it works in Custom Testcase ,but Memory Limit Exceeded when submit


  • 0
    O

    my code is similar and I'm also hitting a memory limit exceeded, more specifically for the test case "222222222222222222222210" 12.

    I think it's broken


Log in to reply
 

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