题意:将字符串排成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. 前端---HTML

    HTML基础 本章内容: 简介 HTML定义 标签定义和属性 HTML5基本结构 HTML5字符集 <head>标签 <title> <base/> <lin ...

  2. PHP 常用字符串函数整理

    PHP语言中的字符串函数也是一个比较易懂的知识.今天我们就为大家总结了将近12种PHP字符串函数,希望对又需要的朋友有所帮助,增加读者朋友的PHP知识库. 1.查找字符位置函数 strpos($str ...

  3. 新手入门Java需要注意的问题

    学习编程,虽然有老师教,但是更重要的事自学.这是很重要的. 现在互联网上面资源太多了,这也就有一个问题:怎么才能在一定时间内学习该知识,掌握该技能呢? 理论联系实践! 学以致用!! 网上的资源太多了, ...

  4. VS2010无法修改资源文件

    最近,因为公司开发的需要,对开发环境进行全面的升级,在这其中也遇到了不少问题,在之后将陆续整理出来,以便以后查看. 之前开发环境:VS2008,ArcGIS9.3,ArcEngine9.3,Oracl ...

  5. 剑指offer题目21-30

    面试题21:包含min函数的栈 import java.util.Stack; public class Solution { private Stack<Integer> stack = ...

  6. Android编译环境搭建(0818-0819)

    1 在虚拟机VMware上安装64位Ubuntu14.04LTS 首先需要安装虚拟机并激活.然后新建虚拟机,选择使用下载好的Ubuntu镜像.注意需要将光驱改为自己下载的,而不是autoinst.is ...

  7. Activity使用startActivityForResult时出现onActivityResult()不执行的问题

    通过使用 startActivityForResult() 和 onActivityResult() 方法可以在Activity之间传递或接收参数.但有时候我们会遭遇onActivityResult( ...

  8. iOS 不让自动锁屏

    [UIApplication sharedApplication].idleTimerDisabled=YES;

  9. 自定义安装php开发环境(1)--apache和php整合

    第一步:安装apache 第二步:下载php核心包php-5.3.3-Win32-VC6-x86.zip.并放入开发环境文件夹C:/phpenv/文件夹下 第三步: 将apache 和php 整合 也 ...

  10. yum 安装 phpmyadmin

    1.安装apache yum -y install httpd httpd-devel 2.安装phpmyadmin yum -y -install phpmyadmin 3.配置phpmyadmin ...