help me please


  • 0
    C

    result is right in my own visual studio but sumbit failed;
    ????

    class Solution
    {
    public:
        string convert(string s, int numRows)
        {
            static string ss(int(s.size()),'G');
    
            int p = 0;
            if (numRows >= int(s.size())||numRows==1)
            {
                return s;
            }
            else
            {
                for (int j = 0; j < numRows; j++)
                {
                    if (j == 0)
                    {
                        for (int i = 0; i < int(s.size()); i++)
                        {
                            if (2 * i*(numRows - 1) < int(s.size()))
                            {
                                ss[p] = s[2 * i*(numRows - 1)];
                                p++;
                                cout << ss << endl;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    else if (j != 0 && j != numRows - 1)
                    {
                        ss[p]=s[j];
                        p++;
                        for (int i = 1; i < int(s.size()); i++)
                        {
                            if (2*i * (numRows - 1) - j < int(s.size()))
                            {
                                ss[p] = s[2*i * (numRows - 1) - j];
                                p++;
    
                            }
                            if (2*i * (numRows - 1) + j < int(s.size()))
                        {
                            ss[p] = s[2*i * (numRows - 1) + j];
                                p++;
    
                            }
                        }
                    }
                    else if (j == numRows - 1)
                    {
                        ss[p]=s[j];
                        p++;
    
                        for (int i = 1; i < int(s.size()); i++)
                        {
                            if ((2*i * (numRows - 1) + j )< int(s.size()))
                        {
                            ss[p] = s[2*i * (numRows - 1) + j];
                                p++;
    
                            }
                        }
    
                    }
                }
            }
    
            return ss;
        }
    
    };
    

Log in to reply
 

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