Guest User

Untitled

a guest
Apr 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. class Solution {
  5. public:
  6. string convert(string s, int numRows) {
  7. if(numRows == 1) return s;
  8. int loop = numRows * 2 - 2;
  9. vector<char> res[numRows];
  10. for(int i = 0 ; i < (int)s.length() ; i++){
  11. if(i % loop < numRows){
  12. res[i % loop].push_back(s[i]);
  13. }else{
  14. res[loop - (i % loop)].push_back(s[i]);
  15. }
  16. }
  17. string ans = "";
  18. for(int i = 0 ; i < numRows ; i++)
  19. for(char x : res[i])
  20. ans += x;
  21. return ans;
  22. }
  23. };
  24.  
  25. int main(){
  26. Solution sol;
  27. auto s = sol.convert("PAYPALISHIRING", 3);
  28. printf("%s\n", s.c_str());
  29.  
  30. }
Add Comment
Please, Sign In to add comment