it works on my pc but won't pass online


  • 0
    C
    class Solution {
    public:
        string convert(string s, int numRows) {
         	int length = s.length();
    	 	int group = numRows * 2 -2;
    	 	if(group == 0)
     			return s;
    	 	string newS = "";
    	 	for(int j = 0; j < numRows; j++)
    	 	{
    	 		int i = 0;
    	 		do
    	 		{
    	 			newS += s[i * group + j];
    	 			if(j != 0 && j != numRows -1)
    	 				newS += s[i * group + 2 * numRows - 2 - j];
    	 			i++;
    	 		} while(i * group + j < length);
    
    	 	}
    	 	return newS;
    
    }
    

    };


Log in to reply
 

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