LeetCode(6)
来源:互联网 发布:售楼软件哪家好 编辑:程序博客网 时间:2024/06/04 01:28
Description :
The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this:
“PAYPALISHIRING” 这个单词被用(之字形)写成了如上图所示 . 我们要实现一个函数 convert(string s, int nRows) 将字符串 s 变成像上图那样的 nRows 行(之字形) , 然后按行把它读出来 . 如图 按行读出来就是 : PAHN-APLSIIG-YIR
string convert(string s, int nRows) { if (nRows <= 1) return s; const int len = (int)s.length(); //创建了一个二维数组,str[row] 保存了每一行的字符串 . string *str = new string[nRows]; int row = 0, step = 1; for (int i = 0; i < len; ++i){ str[row].push_back(s[i]); if (row == 0) step = 1; else if (row == nRows - 1) step = -1; row += step; } s.clear(); for (int j = 0; j < nRows; ++j) { s.append(str[j]); } delete[] str; return s;}
阅读全文
0 0
- LeetCode--6
- LeetCode(6)
- LEetCode(6)
- leetcode 6
- LeetCode(6)
- LeetCode 6 - ZigZag Conversion
- LeetCode 6: ZigZag Conversion
- LeetCode(6)ZigZag Conversion
- Leetcode【6】:ZigZag Conversion
- [leetcode 6] ZigZag Conversion
- LeetCode 6 LRU Cache
- LeetCode 6 ZigZag Conversion
- LeetCode(6) ZigZag Conversion
- [Leetcode] 6 - ZigZag Conversion
- LeetCode 6:《ZigZag Conversion》
- [leetcode 6] ZigZag Conversion
- LeetCode | #6 ZigZag Conversion
- [leetcode] 6 ZigZag Conversion
- python的libev库pyev一点心得
- 小鑫の日常系列故事(五)——卡片游戏
- Java泛型详解
- 纯虚函数
- 文章标题
- LeetCode(6)
- Jsp有哪些内置对象以及作用
- PHP面向对象-----(总体学习路线)
- Web服务器(Apache)与Servlet容器(Tomcat)的区别
- 使用opencv把图片拼接成视频
- ERROR: glib-2.22 gthread-2.0 is required to compile QEMU
- Java中编码解码的处理
- win32 API界面编程---窗口
- vue组件之间的数据通讯小例子