What's wrong with my code?


  • 0
    Y

    The last executed input is "fhjqkecapqsidubmecoqnsrulakerofyyrpivrkkheumyxzdzpvmhmjvpvbg", 43.
    And submission result is Runtime Error.I hope some can help me.

    Here is my code:

    char *c_s;
    int i,len,c_row,num,num_next,c_num;
    len = strlen(s);
    c_s = (char *)malloc(len);
    c_row = 0;num = 0;num_next = 0;c_num = 0;i = 0;
    while(c_num<len)
    {
    	if(c_num==0)
    	{
    		c_s[0] = s[0];
    		c_num++;
    	}
    	else if(num_next >=len)
    	{
    		c_row++;
    		num = c_row;num_next = num;
    		c_s[c_num] = s[num];
    		c_num++;
    	}
    	else if(c_row==0||c_row==nRows)
    	{
    		num_next = num+2*(nRows-1);
    		if(num_next<len)
    		{
    			c_s[c_num] = s[num_next];
    			num = num_next;
    			c_num++;
    		}
    		else
    			continue;
    	}
    	else
    	{
    		if(i/2 == 0)
    		{
    			num_next = num + 2 * (nRows-c_row)-2;
    			i=1;
    		}
    		else
    		{
    			num_next = num + 2 * (c_row + 1) -2;
    			i=0;
    		}
    		if(num_next<len)
    		{
    			c_s[c_num] = s[num_next];
    			num = num_next;
    			c_num++;
    		}
    		else
    			continue;
    	}
    }
    c_s[len] = '\n';
    return c_s;

Log in to reply
 

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