Why? My code running good on VS. But there is a run time error on OJ

  • 0

    Who could find the reason for the following code?
    It's running good on my machine, but has run time error "Last executed input: []" here. Please help me.

    string result = "";
    char tempch;
    int firstLength = strs[0].size();
    int stringsNumber = strs.size();
    	if (stringsNumber == 0) return result;
    if (stringsNumber == 1) return strs[0];
    for (int i = 0; i < firstLength; i++)
    	tempch = strs[0][i];
    	for (int j = 1; j < stringsNumber; j++)
    		if (tempch != strs[j][i]) return result;
    	result += tempch;
    return result;

  • 0

    please check strs.empty() before using strs[0]

      return "";

Log in to reply

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