Created
September 22, 2018 00:46
-
-
Save zhangxiaomu01/97504ae93d8b504334f1a29390ce67ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
string convert(string s, int num) { | |
int len = s.size(); | |
string finalStr; | |
if(num == 1||len<=1) return s; | |
int k = 2 * num - 2; | |
for(int i = 0; i< num; i++) | |
{ | |
for(int j = 0; i + j<len; j = j + k) | |
{ | |
finalStr.push_back(s[i+j]); | |
// get rid of the first and last line | |
if(i!=0 && (i!= num - 1) && (j + k - i < len); | |
finalStr.push_back(s[j+k - i]); | |
} | |
} | |
return finalStr; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment