首页 > 其他 > 详细

leetcode 6

时间:2016-09-27 19:26:36      阅读:175      评论:0      收藏:0      [点我收藏+]

感觉leetcode上面的题用来联系c++语法确实不错

题解:string的运用

 1 class Solution {
 2 public:
 3     string convert(string s, int numRows) {
 4         if(s.size()==0)return "";
 5         if(numRows==1)return s;
 6          int i,k;
 7      string* Thestr;
 8       Thestr=new string[numRows];
 9      i=0;k=0;
10      Thestr[i].push_back(s[k]);
11      while(k+1<s.size())
12      {
13          if(k%(numRows*2-2)<numRows-1)
14          {
15             i++;
16          }
17          else i--;
18          k++;
19          Thestr[i].push_back(s[k]);
20      }
21      string answer="";
22      for(i=0;i<numRows;i++)
23          answer+=Thestr[i];
24      delete []Thestr;
25      return answer;
26     }
27 };

 

leetcode 6

原文:http://www.cnblogs.com/thefirstfeeling/p/5913764.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!