LeetCode 6 ZigZag Conversion

题目

算模拟题吧

class Solution {
public:
    char a[1000][1000];
    int tag[1000][1000];
    string convert(string s, int numRows) {
        
        if(numRows==0||numRows==1)
            return s;
        string ans="";
        int j=0;
        int k=0;
        for(int i=0;i<s.length();i++)
        {
            if(j<numRows)
            {
                a[k][j]=s[i];
                tag[k][j]=1;
                j++;
                continue;
            }
            if(j >= numRows &&j<=numRows+numRows-3)
            {
                tag[++k][numRows+numRows-j-2]=1;
                a[k][numRows+numRows-j-2]=s[i];
                
                j++;
                
                if(j==numRows+numRows-2)
                {
                    k++;
                    j=0;
                }
                continue;
            }
            else
            {
                j=0;
                k++;
                if(j<numRows)
                {
                    a[k][j]=s[i];
                    tag[k][j]=1;
                    j++;
                    continue;
                }
            }
            
        }
        
        for(int p=0;p<=s.length();p++)
        {
            for(int q=0;q<=s.length();q++)
            {
                if(tag[q][p]==1)
                    ans+=a[q][p];
            }
        }
        return ans;
    }
};
posted @ 2019-06-01 11:04  Shendu.CC  阅读(111)  评论(0编辑  收藏  举报