Here is my function in C,I tested in my C project, and it worked .But it cannot be accepted here.


  • 0
    S
    char* convert(char* s, int numRows) {
    char* str = (char*)malloc(strlen(s));
    int t = 1;
    str[0] = s[0];
    if (numRows <= 1)
    {
    	return s;
    }
    else
    {
    	int n = 2 * numRows - 2;
    	for (int k = 0; k < numRows; k++)
    	{
    		for (int i = 1; s[i] != '\0'; i++)
    		{
    			if (i % n == k || i % n == n - k)
    				str[t++] = s[i];
    		}
    	}
    	str[t] = '\0';
    	return str;
    }
    }

  • 0
    L

    Didn't you see the test cases which is not accepted ?


  • 0
    L

    you have not understood the zigzeg patten format.
    your code : all place the string up to down by cols.
    but in the test cases:
    first col : up to down ;second col : down to up ;third col : up to down


  • 0
    S

    Could you give me an example? I tested my code and it shows what you said.Also I have seen the test case in CSDN blog,and the answer is right.But cannot accepted by the test case in Leetcode.


  • 0
    L

    convert("123456789", 4) get String "1726835940"


  • 0
    S

    Yeah,I tried the test case and the answer of my code is totally right. Sorry,maybe it is not the problem of what you said.Anyway, thanks a lot :)


Log in to reply
 

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