<2017年6月>
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

统计

  • 随笔 - 57
  • 文章 - 7
  • 评论 - 0
  • 引用 - 0

常用链接

留言簿

随笔分类

随笔档案

文章分类

文章档案

Blog

Coder 必备技巧

Compiler for Wurq

搜索

  •  

最新评论

阅读排行榜

评论排行榜

【LeeCode 2017/06/24】6. ZigZag Conversion
 1 class Solution {
 2 public:
 3     string convert(string s, int numRows) {
 4         vector<vector<char>> map;
 5         map.resize(numRows);
 6 
 7         for (int i = 0; i < numRows; i++)
 8             map[i].resize(s.length());
 9 
10         int count = 0;
11         int j = 0;
12         while (count < s.length())
13         {
14             int i = 0;
15             while (count<s.length() && i<numRows)
16                 map[i++][j]= s[count++];
17 
18             j++; i--;
19             while (count<s.length() && i>1)
20                 map[--i][j++= s[count++];
21         }
22         string ans = "";
23         for (size_t i = 0; i < numRows;i++){
24             for (size_t j = 0; j < s.length(); j++){
25                 if (map[i][j] != 0)
26                     ans += map[i][j];
27             }
28         }
29         return ans;
30     }
31 };
32 

posted on 2017-06-24 10:50 Wurq 阅读(102) 评论(0)  编辑 收藏 引用 所属分类: 【LeeCode 每日N题】


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理