题意:将字符串排成Z字形。

PAHNAPLSIIGYIR 如果是5的话,是这样排的

P     I

AP   YR

H L G

N  SI

A    I

于是,少年少女们,自己去找规律吧

提示:每个Z字形的字符串和原字符串的每个字母的位子一一映射

class Solution {
public:
string convert(string s, int numRows) {
string t = s;
if(numRows == ) return t;
int k = ;
for(string::size_type i = ; i < s.size(); i += * numRows - ){
t[k++] = s[i];
}
for(int i = ; i < numRows - ; ++i){
for(string::size_type j = i; j < s.size(); j += * numRows - ){
t[k++] = s[j];
if(j + * numRows - - * i< s.size()) {
t[k++] = s[j + * numRows - - * i];
}
}
}
for(string::size_type i = numRows - ; i < s.size(); i += * numRows - ){
t[k++] = s[i];
}
return t;
}
};

Leetcode 6 ZigZag Conversion 字符串处理的更多相关文章

  1. LeetCode 6. ZigZag Conversion & 字符串

    ZigZag Conversion 看了三遍题目才懂,都有点怀疑自己是不是够聪明... 就是排成这个样子啦,然后从左往右逐行读取返回. 这题看起来很简单,做起来,应该也很简单. 通过位置计算行数: P ...

  2. [leetcode]6. ZigZag Conversion字符串Z形排列

    The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...

  3. Java [leetcode 6] ZigZag Conversion

    问题描述: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows ...

  4. Leetcode 6. ZigZag Conversion(找规律,水题)

    6. ZigZag Conversion Medium The string "PAYPALISHIRING" is written in a zigzag pattern on ...

  5. [LeetCode] 6. ZigZag Conversion 之字型转换字符串

    The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...

  6. 蜗牛慢慢爬 LeetCode 6. ZigZag Conversion [Difficulty: Medium]

    题目 The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows li ...

  7. LeetCode 6 ZigZag Conversion 模拟 难度:0

    https://leetcode.com/problems/zigzag-conversion/ The string "PAYPALISHIRING" is written in ...

  8. leetcode 6. ZigZag Conversion

    https://leetcode.com/problems/zigzag-conversion/ 题目: 将字符串转化成zigzag模式. 例如 "abcdefghijkmlnpq" ...

  9. LeetCode 6 ZigZag Conversion(规律)

    题目来源:https://leetcode.com/problems/zigzag-conversion/ The string "PAYPALISHIRING" is writt ...

随机推荐

  1. C# 从excel里面复制的1万6千多条记录粘贴到FCKeditor里面,点保存的时候,保存不了,页面没有反应

    客户那边添加公告,是直接从excel里面复制的,有1万6千多条记录,excel文件有6M多. 编辑器用的FCKeditor,也能粘贴上,就是点保存的时候,执行了一段时间就没有反映了,保存不了. 想着可 ...

  2. LeetCode(四)

    Find Kth Largest Number public class Solution { public int findKthLargest(int[] nums, int k) { retur ...

  3. [DiocpRPC]介绍与安装

    介绍:    Diocp-RPC组件基于DIOCP进行扩展开发,通信协议基于HTTP,遵循RESTFul开发模式,可以用户三层开发.IDE可以支持大于等于D7的IDE,服务端组件支持Win32/Win ...

  4. php插入排序

    //php版插入排序 $arr=array('','5','3','7','6','4','8','2');     for($i=2;$i<count($arr);$i++)     {   ...

  5. SD-WAN技术分析

    1.概述 转载须注明来自 SDNLAB并附上本文链接. 本文链接:http://www.sdnlab.com/17810.html 宽带接入以及Internet骨干网容量的持续提升,促使企业WAN技术 ...

  6. (Python)list的内建函数 filter(), map(), 和 reduce()

    这一节,我们将主要学习用于list的三个内建函数: filter(), map(), 和 reduce(). 1.filter(function, sequence)  逐个从sequence中取一个 ...

  7. Java—继承、封装、抽象、多态

    类.对象和包 1) 面向对象编程(Object Oriented Programming ,简称 OOP):20世纪70年代以后开始流行. 2) 结构化编程与面向对象编程的区别: A. 在结构化编程中 ...

  8. json+servlet+ajax

    json-lib-2.3-jdk15.jar commons-beanutils-1.7.0.jar commons-httpclient-3.1.jar commons-lang-2.3.jar c ...

  9. Python-pycharm

    进入博客园的第一篇随笔,作为一个编程菜鸟,最近在学习Python,为毕设做准备.总觉得Python自带的idle不太好用,一位“大鸟”向我推荐了pycharm,于是我就抱着试试看的态度下了一个,目前感 ...

  10. Remote Desktop Connection from Windows 7 to Ubuntu 12.04

    $sudo apt-get install xrdp $cd ~ $sudo vim .xsession gnome-session --session=ubuntu-2d 在windows下进行远程 ...