/* 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的更多相关文章

  1. 【leetcode❤python】 6. ZigZag Conversion

    #-*- coding: UTF-8 -*- #ZigZag Conversion :之字型class Solution(object):    def convert(self, s, numRow ...

  2. 64. ZigZag Conversion

    ZigZag Conversion The string "PAYPALISHIRING" is written in a zigzag pattern on a given nu ...

  3. No.006 ZigZag Conversion

    6. ZigZag Conversion Total Accepted: 98584 Total Submissions: 398018 Difficulty: Easy The string &qu ...

  4. leetcode第六题 ZigZag Conversion (java)

    ZigZag Conversion The string "PAYPALISHIRING" is written in a zigzag pattern on a given nu ...

  5. leetcode题解 6.ZigZag Conversion

    6.ZigZag Conversion 题目: The string "PAYPALISHIRING" is written in a zigzag pattern on a gi ...

  6. 6.[leetcode] ZigZag Conversion

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

  7. 字符串按照Z旋转90度然后上下翻转的字形按行输出字符串--ZigZag Conversion

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

  8. LeetCode--No.006 ZigZag Conversion

    6. ZigZag Conversion Total Accepted: 98584 Total Submissions: 398018 Difficulty: Easy The string &qu ...

  9. leetcode-algorithms-6 ZigZag Conversion

    leetcode-algorithms-6 ZigZag Conversion The string "PAYPALISHIRING" is written in a zigzag ...

随机推荐

  1. mysql事务与mysql储存引擎

    事务概念及存储引擎 1.0 为何要事务? 先来看一个场景,银行转账汇款: 李彦宏和周鸿祎天天打架,现在让李彦宏给周鸿祎转款1000 元 设计如下表 account表 编号(id)用户名(user)金额 ...

  2. cookie和会话状态的工作原理

    一:存在两种类型的cookie: 1>会话cookie (session cookie)        不设置过期时间,则表示这个cookie生命周期为浏览器会话期间,只要关闭浏览器窗口,   ...

  3. ANT教程经典

    Ant是一个Apache基金会下的跨平台的构件工具,它可以实现项目的自动构建和部署等功能.在本文中,主要让读者熟悉怎样将Ant应用到Java项目中,让它简化构建和部署操作. 一.            ...

  4. 专注于提高“人肉测试”效率,Bugtags已完成600万元天使轮融资

    导语:近日,专注于移动测试的缺陷发现及管理工具“Bugtags”创始人张磊独家透露,Bugtags已完成600万元天使轮投资,投资方为高捷资本. 近日,专注于移动测试的缺陷发现及管理工具“Bugtag ...

  5. iOS开发之检查更新

    iOS设备检查更新版本: #pragma mark - 检查更新 - (void)checkUpdateWithAPPID:(NSString *)APPID { //获取当前应用版本号 NSDict ...

  6. Hibernate的dialect大全

    RDBMS 方言 DB2 org.hibernate.dialect.DB2Dialect DB2 AS/400 org.hibernate.dialect.DB2400Dialect DB2 OS3 ...

  7. 20145305 《Java程序设计》实验一

    实验名称 实现凯撒密码,并进行测试. 实验内容 它是一种代换密码.据说凯撒是率先使用加密函的古代将领之一,因此这种加密方法被称为恺撒密码. 凯撒密码作为一种最为古老的对称加密体制,在古罗马的时候都已经 ...

  8. Java实现单向链表的增删改查

    class List<T> { private class Node { private T data; private Node next; private Node(T data) { ...

  9. 使用go tool pprof分析内存泄漏、CPU消耗

    go中提供了pprof包来做代码的性能监控,在两个地方有包: net/http/pprof runtime/pprof 其实net/http/pprof中只是使用runtime/pprof包来进行封装 ...

  10. js注意事项

    在数组顶部插入一条数据 data.result.unshift({ Value: 'all', Text: '请选择分类' }); 执行iframe中的javascript方法 window.fram ...