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 ...
随机推荐
- poj 1011 Sticks
Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 126238 Accepted: 29477 Descrip ...
- Ecshop(二次开发) - 后台添加左侧菜单导航
1.链接地址:修改 admin\includes\inc_menu.php 文件. $modules['17_syn_data']['view_syn'] = 'synchroni ...
- eclipse导出jar包
第一种:普通类导出jar包,我说的普通类就是指此类包含main方法,并且没有用到别的jar包. 1.在eclipse中选择你要导出的类或者package,右击,选择Export子选项: 2.在弹出的对 ...
- iOS应用架构谈:架构设计的方法论
缘由 之前安居客iOS app的第二版架构大部分内容是我做的,期间有总结了一些经验.在将近一年之后,前同事zzz在微信朋友圈上发了一个问题:假如问你一个iOS or Android app的架构,你会 ...
- windowns--HANDLE,
HANDLE: 在windows程序中,有各种各样的资源(窗口.图标.光标等),系统在创建这些资源时会为他们分配内存,并返回标示这些资源的标示号,即句柄. 句柄指的是一个核心对象在某一个进程中的唯一索 ...
- java小程序 示例 菲薄垃圾数列
package com.test; import java.util.Scanner; import org.junit.Test; import com.sun.xml.internal.ws.ap ...
- [Flex] IFrame系列 —— 在flex的web应用中嵌入html的方法
在flex的web应用中,我们往往必须有嵌入html的需求,这时候你会发现IFrame很有用! flex而且可以和html中的JavaScript进行交互,flex可以通过iframe调用到html中 ...
- HOST ip is not allowed to connect to this MySql server
报错:1130-host ... is not allowed to connect to this MySql server 解决方法: 1. 改表法. 可能是你的帐号不允许从远程登陆,只能在loc ...
- easyUi中的一段漂亮代码之将list转换成tree.
function convert(rows){ function exists(rows, parentId){ for(var i=0; i<rows.length; i++){ if (ro ...
- VML/SVG在Web开发中一些常见的框架
1.借鉴自: http://www.codefans.net/soft/3061.shtml 来源于网上. flowchart.js http://adrai.github.io/flowchart ...