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 ...
随机推荐
- ADF_General JSF系列2_创建JSF类型的页面向导
2015-02-17 Created By BaoXinjian
- php命名空间学习
在一个命名空间中,当 PHP 遇到一个非限定的类.函数或常量名称时,它使用不同的优先策略来解析该名称. 1.类名称总是解析到当前命名空间中的名称.因此在访问系统内部或不包含在命名空间中的类名称时,必须 ...
- 基于redis的分布式锁
<?php /** * 基于redis的分布式锁 * * 参考开源代码: * http://nleach.com/post/31299575840/redis-mutex-in-php * * ...
- C++程序设计原理与实践
std_lib_facilities.h和VS下创建C++程序方法:下载 目录: 001. Hello,World!
- 关于Rotation和Quaternion的一些问题
当我们使用unity的时候,面对一个物体,一个不可避免的问题就是:控制物体的旋转. unity的Transform组件的第二个属性Rotation为我们提供控制物体旋转的功能.在一个物体的Inspec ...
- MethodNotAllowedHttpException
原因:1.没有加表单{{csrf_field()}}:2.除get提交以外,其它提交方式都要csrf_token();3.提交的路由非法,没有定义.
- js 节流函数 throttle
/* * 频率控制 返回函数连续调用时,fn 执行频率限定为每多少时间执行一次 * @param fn {function} 需要调用的函数 * @param delay {number} 延迟时间, ...
- sqlite 时间排序
select * from tb_QuantifyResult where iSamplingOrCalibration = 1 and cComponentName <> ' + Quo ...
- MVC 4 与WebForm 混合应用 WebApi 发布常见问题
1.所有应用的MVC相关程序集编译时要选择复制到本地,需要用到的程序如下图 2.IIS设置: 因为 IIS 7/8 采用了更安全的 web.config 管理机制,默认情况下会锁住配置项不允许更改.运 ...
- How to get the date N days ago in Python
from datetime import datetime, timedelta N = 2 date_N_days_ago = datetime.now() - timedelta(days=N) ...