6. Z 字形变换
水题
n方即可
class Solution { public: string convert(string s, int numRows) { if (numRows == 1) return s; int len = s.length(); int cnt = 0; int str[1001][1001]; memset(str, -1, sizeof(str)); int j = 0; while(cnt < len) { if(j % (numRows - 1) == 0) for(int i = 0; i < numRows && cnt < len; i++) str[i][j] = s[cnt++] - 'a'; else { int k = j % (numRows - 1); int i = numRows - 1 - k; str[i][j] = s[cnt++] - 'a'; } j++; } string ret = ""; for(int i = 0; i < numRows; i++) { for(int k = 0; k < 1000; k++) if(str[i][k] != -1) { // cout << str[i][k] << endl; ret += 'a' + str[i][k]; } } return ret; } };
自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。

浙公网安备 33010602011771号