题目:

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   N
A P L S I I G
Y I R

And 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".

Zigzag:即循环对角结构.

向下循环:nRows

斜角线循环

重复...

#include <string>
#include <iostream>
using namespace std; string convert(string s,int nRows){
if(nRows==) return s; string res[nRows];
int i==,j,gap=nRows-; while(i<s.size()){
for(j=;j<nRows && i<s.size();j++) res[j]+=s[i++];
for(j=gap;j> && i<s.size();j--) res[j]+=s[i++];
} string ret="";
for(i=;i<nRows;i++){
ret+=res[i];
}
return ret;
}

ZigZag-LeetCode的更多相关文章

  1. [LeetCode] Zigzag Iterator 之字形迭代器

    Given two 1d vectors, implement an iterator to return their elements alternately. For example, given ...

  2. [LeetCode] Binary Tree Zigzag Level Order Traversal 二叉树的之字形层序遍历

    Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to ...

  3. [LeetCode] ZigZag Converesion 之字型转换字符串

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

  4. ZigZag Conversion leetcode java

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

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

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

  6. leetcode 6. ZigZag Conversion

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

  7. LeetCode Zigzag Iterator

    原题链接在这里:https://leetcode.com/problems/zigzag-iterator/ 题目: Given two 1d vectors, implement an iterat ...

  8. LeetCode 6 ZigZag Conversion(规律)

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

  9. [LeetCode]题解(python):103 Binary Tree Zigzag Level Order Traversal

    题目来源 https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/ Given a binary tree, re ...

  10. [LeetCode][Python]ZigZag Conversion

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/zigzag- ...

随机推荐

  1. 网站的优化----首页优化---app调取服务端数据

    高并发经常会发生在有大活跃用户量来访问网站的某个点,例如用户高聚集的业务场景中,如:抢购,促销等.为了让用户流畅的访问网站,来根据自己的业务设计适合系统的处理方案. //对于APP网站首页数据,通常是 ...

  2. BIOS讲解

    首先  BIOS其实没什么神奇的 就是  Bisic input/output System,所以基本输入输出系统是一块装入了启动和自检程序的EPROM或EEPROM集成块,实际上它是被固化在计算机R ...

  3. Swift--存储属性-备

    Swift中的属性分为存储属性和计算属性,存储属性就是Objective-C中的数据成员,计算属性不存储数据,但可以通过计算其他属性返回数据. 存储属性可以存储数据,分为常量属性(用关键字let定义) ...

  4. 修改UITextField Placeholder的颜色

    修改UITextField Placeholder的颜色 1 第一种情况只是修改颜色等文字属性 创建属性字典 NSDictionary *attrsDic = @{ NSForegroundColor ...

  5. Bash的几个知识点

    1. 区别 builtin command, external command,bash script. 用builtin command(hash.type.command),而不是which命令( ...

  6. 64位调试器花费的时间比预期的要长(A 64-bit debugging operation is taking longer than expected)

    在stackoverflow上找到解决方案的: http://stackoverflow.com/questions/21329899/vs2013-professional-local-64-bit ...

  7. BZOJ1270: [BeijingWc2008]雷涛的小猫

    1270: [BeijingWc2008]雷涛的小猫 Time Limit: 50 Sec  Memory Limit: 162 MBSubmit: 836  Solved: 392[Submit][ ...

  8. 【转】Android将Activity打成jar包供第三方调用(解决资源文件不能打包的问题)

    Android中引入第三方Jar包的方法(java.lang.NoClassDefFoundError解决办法) 鼠标右键项目,然后属性,然后java buildpath 然后order and ex ...

  9. cf493A Vasya and Football

    A. Vasya and Football time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  10. paip.索引优化---sql distict—order by 法

    paip.索引优化---sql distict—order by 法 作者Attilax ,  EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog ...