leetcode 6. ZigZag Conversion

来源:互联网 发布:mysql strict mode 编辑:程序博客网 时间:2024/05/21 18:32

找规律

class Solution {public:     char word[1000];    string convert(string s, int numRows) {        int cnt  = 0, n = s.length();        int step = max(2*numRows-2,1);        for(int i = 0;i < numRows; i++){            int shift = 2*numRows-2-2*i;            for(int j = i;j < n; j+=step){                word[cnt++] = s[j];                if(i != 0 && i != numRows-1){                    if(j+shift < n)                        word[cnt++] = s[j+shift];                }            }        }        word[cnt]='\0';        return word;    }};


0 0
原创粉丝点击