leetcode - ZigZag Conversion
来源:互联网 发布:linux 获取系统时区 编辑:程序博客网 时间:2024/03/29 18:23
The string "PAYPALISHIRING"
is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)
P A H NA P L S I I GY I RAnd then read line by line:
"PAHNAPLSIIGYIR"
Write the code that will take a string and make this conversion given a number of rows:
string convert(string text, int nRows);
convert("PAYPALISHIRING", 3)
should return "PAHNAPLSIIGYIR"
.
class Solution {public: std::string convert(std::string s, int nRows) {if(nRows==1) { return s; } std::string result; int t = nRows*2-2; for(int i = 0;i<=t/2;++i) { for(int j = 0;j<s.size();++j) { if(j%t==i||j%t==t-i) { result+= s[j]; } } } return result; }};
0 0
- LeetCode: ZigZag Conversion
- LeetCode : ZigZag Conversion
- leetcode 13:zigzag conversion
- [LeetCode] Zigzag Conversion
- LeetCode 6 - ZigZag Conversion
- Leetcode : ZigZag Conversion
- 【leetcode】Zigzag Conversion
- [LeetCode]ZigZag Conversion
- leetcode ZigZag Conversion
- LeetCode-ZigZag Conversion
- LeetCode ZigZag Conversion
- LeetCode 6: ZigZag Conversion
- leetcode-006:ZigZag Conversion
- Leetcode: ZigZag Conversion
- [LeetCode]ZigZag Conversion
- [LeetCode] ZigZag Conversion
- [LeetCode]ZigZag Conversion
- leetcode: ZigZag Conversion
- java PLAY框架学习笔记--入门
- Token验证失败
- UITextField可以设置右边和右边的图片
- Java中访问权限控制
- iOS弹键盘、收键盘
- leetcode - ZigZag Conversion
- 当类是ToolBar时候,设置代理不能用delegate关键字
- 线程(四)Monitor
- 关于{ 正在创建 .unsuccessfulbuild 因为已指定“AlwaysCreate” }的解决方案
- Asterisk呼叫中心之由xml生成结构菜单(三)
- Ubuntu14.04下JDK安装
- 让某种视图view成为键盘输入辅助工具
- vim中跳转到头文件
- glPushMatrix() glPopMatrix() GL_DEPTH_TEST