题目如下:

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

  1. LeetCode(6) ZigZag Conversion

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

  2. (字符串)ZigZag Conversion

    [解析] 第一次看到这个题目的人,可能不知道ZigZag是什么意思,简单解释一下,就是把字符串原顺序012345……按下图所示排列: 发现所有行的重复周期都是 2 * nRows - 2 对于首行和末 ...

  3. 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 ...

  4. LeetCode(275)H-Index II

    题目 Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimi ...

  5. LeetCode(220) Contains Duplicate III

    题目 Given an array of integers, find out whether there are two distinct indices i and j in the array ...

  6. LeetCode(154) Find Minimum in Rotated Sorted Array II

    题目 Follow up for "Find Minimum in Rotated Sorted Array": What if duplicates are allowed? W ...

  7. 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 ...

  8. LeetCode(116) Populating Next Right Pointers in Each Node

    题目 Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode * ...

  9. 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 ...

随机推荐

  1. 好莱坞原则—Spring的IOC容器

    IOC容器的概念,之前在学习SSH的时候,就有接触过.但那时候也仅仅是知道这么个概念,认为它非常难理解.事实上并非它难理解,而是我并没有停下来好好对它总结梳理过. IOC(Inversion of C ...

  2. 三种SVM的对偶问题

    一.SVM原问题及要变成对偶问题的解决办法 对于SVM的,我们知道其终于目的是求取一分类超平面,然后将新的数据带入这一分类超平面的方程中,推断输出结果的符号,从而推断新的数据的正负. 而求解svm分类 ...

  3. (转)C/C++ 宏详解

    众多C++书籍都忠告我们C语言宏是万恶之首,但事情总不如我们想象的那么坏,就如同goto一样.宏有一个很大的作用,就是自动为我们产生代码.如果说模板可以为我们产生各种型别的代码(型别替换),那么宏其实 ...

  4. WIN32常用

    //1.设置窗口大小 MoveWindow(hWnd, , , + , + , FALSE); //放在InitInstance用于设置位置与窗口大小 //传递句柄就可以绘图 //2.双缓冲绘图模式 ...

  5. avalon过滤

    <html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    ...

  6. 【原创】关于java中的lock

    看了下java中高性能锁Lock,其中有如下: ReentrantLock:独占锁,类似于synchronized,不过锁的粒度更小 ReadWriteLock(ReentrantReadWriteL ...

  7. STM8S103-STVD建立汇编代码项目

    转载:http://blog.csdn.net/u010093140/article/details/49983397 STVD本来就比较少人用,STVD汇编就更少人用了,不过STM8汇编我自己还是满 ...

  8. 3ds Max怎么制作亮木材质的球体

    3DSMax怎么制作亮木材质的球体?3DSMax中想要设计一款亮木材质的球体,该怎么设置呢?下面我们就来看看详细的教程,需要的朋友可以参考下! 1.运行软件,选择材质编辑器图标: 3.双击拖拽出的材质 ...

  9. LAMP 建立 Wordpress 站点 Linux Apache MariaDB PHP

    使用LAMP建立Wordpress, 要求如下: 准备工作: VMware 14 CentOS 7.4 最小化 安装镜像 Wordpress 安装包,  下载 预热: 使用VMware新建4台虚拟机, ...

  10. Sublime Text编辑器配置Python解释器简易教程

    前天在微信上遇到一个小伙伴问我一个关于Sublime text配置Python解释器的问题,可能是初学者,对这方面还不是很懂,想使用快捷键但是徒劳一场,因为缺少Python解释器,直接按下快捷键Ctr ...