Leetcode006 ZigZag Conversion
/* simple simulation algorithm
* we cann`t make sure the size of the string,
* so it had better to storage in vector.
* show[] to buffer the new order of the string
*/
class Solution {
public:
string convert(string s, int numRows) {
string result;
vector<char> show[numRows];
for(int index=;index<s.size();) //divide into two parts
{
for(int i=;i<numRows;i++) //simple row full storage
{
show[i].push_back(s[index++]);
if(index==s.size())break;
}
for(int i=;i<=numRows-;i++) //middle row only only one char storaged
{
for(int j=numRows-;j>=;j--)
{
if(i+j==numRows-)show[j].push_back(s[index++]);
if(index==s.size())break;
}
if(index==s.size())break;
}
}
for(int i=;i<numRows;i++)
{
for(int j=;j<show[i].size();j++)result+=show[i][j];
}
return result;
}
};
Leetcode006 ZigZag Conversion的更多相关文章
- 【leetcode❤python】 6. ZigZag Conversion
#-*- coding: UTF-8 -*- #ZigZag Conversion :之字型class Solution(object): def convert(self, s, numRow ...
- 64. ZigZag Conversion
ZigZag Conversion The string "PAYPALISHIRING" is written in a zigzag pattern on a given nu ...
- No.006 ZigZag Conversion
6. ZigZag Conversion Total Accepted: 98584 Total Submissions: 398018 Difficulty: Easy The string &qu ...
- leetcode第六题 ZigZag Conversion (java)
ZigZag Conversion The string "PAYPALISHIRING" is written in a zigzag pattern on a given nu ...
- leetcode题解 6.ZigZag Conversion
6.ZigZag Conversion 题目: The string "PAYPALISHIRING" is written in a zigzag pattern on a gi ...
- 6.[leetcode] ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...
- 字符串按照Z旋转90度然后上下翻转的字形按行输出字符串--ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...
- LeetCode--No.006 ZigZag Conversion
6. ZigZag Conversion Total Accepted: 98584 Total Submissions: 398018 Difficulty: Easy The string &qu ...
- leetcode-algorithms-6 ZigZag Conversion
leetcode-algorithms-6 ZigZag Conversion The string "PAYPALISHIRING" is written in a zigzag ...
随机推荐
- 转-Activity之间数据传递之Intent数据传递
Intent意图 可用于Activity之间的数据传递,一般可分为下面两种情况,从当前Activity传递到目标Activity后有无返回值: 1.传递后无返回值的情况: 1 2 3 4 5 6 7 ...
- 用happen-before规则重新审视DCL(转)
编写Java多线程程序一直以来都是一件十分困难的事,多线程程序的bug很难测试,DCL(Double Check Lock)就是一个典型,因此对多线程安全的理论分析就显得十分重要,当然这决不是说对多线 ...
- websphere应用程序的使用
1.服务器板块 1.1 jvm虚拟机的通用参数: agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=7777Dcom.ibm.w ...
- JS获取两个日期的月份差
function getMonthBetween(startDate,endDate){ startDate=new Date(startDate.replace(/-/g,'/')); endDat ...
- jQuery 常见操作实现方式
一个优秀的 JavaScript 框架,一篇 jQuery 常用方法及函数的文章留存备忘. jQuery 常见操作实现方式 $("标签名") //取html元素 document. ...
- DIY--主板跳线接法
如下图:
- substr
substr(string,start,length) string - 指定的要截取的字符串 start - 必需,规定在字符串的何处开始 正数 - 在字符串的指定位置开始 负数 - 在从字符串结尾 ...
- 线程间操作无效: 从不是创建控件“”的线程访问它~~~的解决方法~ 线程间操作无效: 从不是创建控件“Control Name'”的线程访问它问题的解决方案及原理分析
看两个例子,一个是在一个进程里设置另外一个进程中控件的属性.另外一个是在一个进程里获取另外一个进程中控件的属性. 第一个例子 最近,在做一个使用线程控制下载文件的小程序(使用进度条控件显示下载进度)时 ...
- [SQL] 不合并重复数据 union all
select * from A union select * from B --不合并重复行 select * from A union all select * from B --如果要对字段进行排 ...
- MS SQL SERVER 数据库日志压缩方法与代码
MS SQL性能是很不错的,但是数据库用了一段时间之后,数据库却变得很大,实际的数据量不大.一般都是数据库日志引起的!数据库日志的增长可以达到好几百M. DUMP TRANSACTION [数据库名] ...