ZigZag-LeetCode
题目:
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的更多相关文章
- [LeetCode] Zigzag Iterator 之字形迭代器
Given two 1d vectors, implement an iterator to return their elements alternately. For example, given ...
- [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 ...
- [LeetCode] ZigZag Converesion 之字型转换字符串
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...
- ZigZag Conversion leetcode java
题目: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows l ...
- LeetCode 6 ZigZag Conversion 模拟 难度:0
https://leetcode.com/problems/zigzag-conversion/ The string "PAYPALISHIRING" is written in ...
- leetcode 6. ZigZag Conversion
https://leetcode.com/problems/zigzag-conversion/ 题目: 将字符串转化成zigzag模式. 例如 "abcdefghijkmlnpq" ...
- LeetCode Zigzag Iterator
原题链接在这里:https://leetcode.com/problems/zigzag-iterator/ 题目: Given two 1d vectors, implement an iterat ...
- LeetCode 6 ZigZag Conversion(规律)
题目来源:https://leetcode.com/problems/zigzag-conversion/ The string "PAYPALISHIRING" is writt ...
- [LeetCode]题解(python):103 Binary Tree Zigzag Level Order Traversal
题目来源 https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/ Given a binary tree, re ...
- [LeetCode][Python]ZigZag Conversion
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/zigzag- ...
随机推荐
- java学习笔记 (2) —— Struts2类型转换、数据验证重要知识点
1.*Action.conversion-properties 如(point=com.test.Converter.PointListConverter) 具体操作类的配置文件 2.*Action. ...
- 菜鸟做HTML5小游戏 - 翻翻乐
记录下开放过程.做小游戏开发,又要跨平台,flash又不支持iPhone,html5是最好的选择. 先看看最后效果: 好了,开始demo. 1.准备工作: 图片素材(省略...最后代码一起打包) 了解 ...
- php 文件操作中几种方法整理
1.获取文件夹下所有文件个数 echo ShuLiang("../0503lianxi"); function ShuLiang($filename) { if(is_dir($f ...
- php 之 文件操作(0524)
php中文件包含两种:文件,文件夹.文件夹又称目录 新建一个文件aa.txt和一个文件夹text,text文件夹下又包含bb.txt 一.判断文件类型filetype("./aa.txt&q ...
- php 之 注册审核(0523)
当注册后,先将信息保存到session,通过审核后才会添加到数据库中, 审核通过后状态变为已通过,这时添加到数据库中的信息进行登录.若发现此用户的不良行为,可以撤销通过. 注册页面: <!DOC ...
- 关于Windows高DPI的一些简单总结(Window上一般默认是96 dpi 作为100% 的缩放比率)
我们知道,关于高DPI的支持, Windows XP时代就开始有了, 那时关于高DPI的支持比较简单, 但是从Vista/Win7 到现在Win8 /Win8.1, Windows关于高DPI的支持已 ...
- Quartz集成springMVC 的方案一
Quartz是一个开放源码项目,专注于任务调度器. springMVC 具体的搭建框架就不具体说明,接下来直接描述把Quartz集成到springMVC 框架中. 步骤: 1.引入所需要的jar包 2 ...
- zoj 3811 Untrusted Patrol(bfs或dfs)
Untrusted Patrol Time Limit: 3 Seconds Memory Limit: 65536 KB Edward is a rich man. He owns a l ...
- linux shell在while中用read从键盘输入
系统是ubuntu 14.04 64bit,之前曾想安装Stream来玩dota2,但最终没成功.由于Stream只有32bit,安装Stream时也安装了大量32bit的库.删除Stream后,这些 ...
- delphi 简单的删除字符串尾部数字的代码
delphi 简单的删除字符串尾部数字的代码 方式一: function FilterShowName(const sName: String): String; var I: Integer; b ...