Runtime error for "bb"? Local tested (resolved)


  • 0
    L

    For "bb", the expected result should be "bb" right? I local tested.
    Am I misundertood the question?

    class Solution {
    public:
    string longestPalindrome(string s) {
    	for (int i = 0; i < s.length() - 1; i++){
    		for (int start = 0; start <= i; start++){
    			int end = i - start;
    			if (isPalindrome(s, start, s.length()-1 -end)){
    				return s.substr(start, s.length()-i);
    			}
    		}
    	}
    }
    
    bool isPalindrome(string& s, int start, int end){
    	while (start <= end){
    		if (s[start] != s[end])
    		{
    			return false;
    		}
    
    		start++;
    		end--;
    	}
    
    	return true;
    }
    

    };


  • 0
    L

    got the problem.
    Not all code path returns the string type.
    (no compilation issue in Visual Studio)


Log in to reply
 

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