[LeetCode] Zigzag Conversion
2015-09-14 14:53
423 查看
The key challenge to this problem is to make the code clean. This post has shared a nice example, which is rewritten below in C++.
class Solution { public: string convert(string s, int numRows) { vector<string> vs(numRows, ""); int n = s.length(), i = 0; while (i < n) { for (int j = 0; j < numRows && i < n; j++) vs[j].push_back(s[i++]); for (int j = numRows - 2; j >= 1 && i < n; j--) vs[j].push_back(s[i++]); } string zigzag; for (string v : vs) zigzag += v; return zigzag; } };
相关文章推荐
- Django URL传递参数的方法总结
- 自学Swift-斯坦福笔记整理(十二) Physics based Dynamic Animation
- Win10微软小娜无法连接网络怎么办?微软小娜无法连接网络问题解决方法
- Jquey学习
- (转)shell 脚本date时间格式
- MFC窗口风格 说明及在c#中的定义使用
- ViewPager onPageChangeListener总结
- ScrollView嵌套ListView冲突
- 手机禁止浏览器往下拉
- access and faccessat 按照实际用户Id和实际组ID进行文件权限测试
- Linux 下curl模拟Http 的get or post请求。
- iOS学习笔记: 初步探索KVC & KVO
- IBM 关于 Java 深入学习的技术资料
- IAP
- 自学Swift-斯坦福笔记整理(十一) Unwind segue alert
- unrar
- 绿盟科技发布2015软件定义安全SDS白皮书
- linux设置ulimit方法
- C#中ComboBox的SelectedIndexChanged事件获取Tag值
- 逻辑思维1:迷宫