LeetCode(6)ZigZag Conversion
题目如下:

C++代码:
#include <iostream>
#include <string>
using namespace std;
class Solution {
public:
string convert(string s, int numRows) {
if (numRows <= || s.length() <= numRows)
return s;
string result;
int ZigSpan = * numRows - ;
for (int i = ; i < numRows; i++){
for (int j = i; j < s.length(); j += ZigSpan){
result.push_back(s[j]);
if (i != && i != numRows - ){
int t = j + ZigSpan - * i;
if (t < s.length())
result.push_back(s[t]);
}
}
}
return result;
}
};
void ZigZag(){
string s = "abcdefghijklmn";
Solution *ss = new Solution();
cout << ss->convert(s, ) << endl;
}
LeetCode(6)ZigZag Conversion的更多相关文章
- LeetCode(6) ZigZag Conversion
题目 The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows li ...
- (字符串)ZigZag Conversion
[解析] 第一次看到这个题目的人,可能不知道ZigZag是什么意思,简单解释一下,就是把字符串原顺序012345……按下图所示排列: 发现所有行的重复周期都是 2 * nRows - 2 对于首行和末 ...
- LeetCode(107) Binary Tree Level Order Traversal II
题目 Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from l ...
- LeetCode(275)H-Index II
题目 Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimi ...
- LeetCode(220) Contains Duplicate III
题目 Given an array of integers, find out whether there are two distinct indices i and j in the array ...
- LeetCode(154) Find Minimum in Rotated Sorted Array II
题目 Follow up for "Find Minimum in Rotated Sorted Array": What if duplicates are allowed? W ...
- LeetCode(122) Best Time to Buy and Sell Stock II
题目 Say you have an array for which the ith element is the price of a given stock on day i. Design an ...
- LeetCode(116) Populating Next Right Pointers in Each Node
题目 Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode * ...
- LeetCode(113) Path Sum II
题目 Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given ...
随机推荐
- 获取json数据后在 地图上打点,根据 json不断移动点的位置
<?php echo <<<_END <!doctype html> <html> <head> <meta charset=&quo ...
- web forms page和control的生命周期life cycle交互,以及page生命周期中每个event中需要做什么事情
只有 page_load和page_init这些可以autoeventwireup RenderControl只提供override public override void RenderContro ...
- JAVA设计模式之【外观模式】
通过引入一个外观角色来简化客户端与子系统之间的交互. 顾客无需直接和茶叶.茶具.开水等交互,整个泡茶过程由服务员来完成,顾客只需与服务员交互即可. 通过引入一个外观角色可以降低原有系统的复杂度,同时降 ...
- ThinkPHP5.0最最最最最简单实例
ThinkPHP5.0最最最最最简单实例 一.效果图 二.操作步骤 1.用mysql数据库建立数据库 2.按照ThinkPHP官网的指示装好ThinkPHP5.0 tp5里面的目录结构如下: 3.配置 ...
- HOOK劫持自己
#include <stdio.h> #include <stdlib.h> #include <Windows.h> #include "detours ...
- Kali linux 2016.2(Rolling)中的Exploits模块详解
简单来将,这个Exploits模块,就是针对不同的已知漏洞的利用程序. root@kali:~# msfconsole Unable to handle kernel NULL pointer der ...
- java高级——暴力反射
反射,java中一个比较高级的应用,主要和开发中的框架紧密相连.今天我们就介绍一下他的特性之一,暴力反射.(听名字很恐怖呦) package wo; public class A{ public St ...
- Day92
# session:用于保存客户端历史访问的信息# BeautifulSoup是一个模块,该模块用于接收一个HTML或XML字符串,然后将其进行格式化,# 之后遍可以使用他提供的方法进行快速查找指定元 ...
- 脚本2,从1到99 ,添加用户user1,user2,。。。 user99
脚本2,从1到99 ,添加用户user1,user2,... user99 如果用户user$存在,脚本显示用户存在,否则添加用户,并显示添加用户成功. 脚本如下 [root@localhost ho ...
- debug和release的区别
Debug和Release,主要是针对其面向的目标不同的而进行区分的.Debug通常称为调试版本,通过一系列编译选项的配合,编译的结果通常包含调试信息,而且不做任何优化,以为开发人员提供强大的应用程序 ...