Why my code is wrong answer??!!!


  • 0
    W

    i can not find the problem!

    class Solution {
    public:
    string convert(string s, int nRows) {
        int length = s.size();
        if (length <= nRows || nRows == 1) 
            return s;
        char chars[length-1];
        int step = 2*(nRows-1);
        int count=0;
        
        for(int i=0;i<nRows;i++)
        {
            int interval = step -2*i;
            for(int j=i;j<length;j+=step)
            {
                chars[count] = s.at(j);
                count++;
                if(interval<step && interval>0 && (j+interval)<length && count<length)
                    {
                        chars[count] = s.at(j+interval);
                        count++;
                    }
            }
        }
        string result = chars;
        
        return result;
    }
    

    };


Log in to reply
 

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