Runtime Error in Calculation C# longest substring problem


  • 0
    N

    Hello! I am having this problem "Runtime Error". Actually it is working locally with the sample that is failing in OJ. I have no idea whats going on. Actually, I do believe that it should fail with everything but it is not failing at all and it is just with one case, the longest one.

    private int CalculateLongestSubStringInSequence(string str)
    {
    	if (str=="") {
    		return 0;
    	}
    	return CalculateLongestSubStringInSequence (str.ToCharArray (), 0);
    }
    
    private int CalculateLongestSubStringInSequence(char[] array,int startCmpIndex){
    
    	int stopIndex = CalculateStopIndex (array,startCmpIndex,array.Length);
    	int longestSubString = stopIndex + 1;
    
    	if ((array.Length - startCmpIndex)>longestSubString) {
    		int longestSubString2 = CalculateLongestSubStringInSequence (array,startCmpIndex+1);
    		if (longestSubString2 > longestSubString) {
    			longestSubString = longestSubString2;
    		}
    	}
    	return longestSubString;
    }
    
    private int CalculateStopIndex(char[] array,int startCmpIndex,int stopCompareIndex)
    {
    	int stopIndex = 0;
    
    	for (int i = startCmpIndex + 1; i < stopCompareIndex; i++) {
    
    		if (array[startCmpIndex] == array[i]) {
    			break;
    		}
    		stopIndex++;
    	}
    
    	if ((stopIndex - startCmpIndex) > 0) {
    		return CalculateStopIndex(array,startCmpIndex+1,startCmpIndex+stopIndex)+1;
    	} else {
    		return stopIndex;
    	}
    }

Log in to reply
 

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