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 ...
随机推荐
- 37、ifconfig命令
很多windows很熟悉ipconfig命令行工具.它被用来获取网络接口配置信息并对此进行改动.Linux系统拥有一个类似的工具,也就是ifconfig(interfaces config). 通常须 ...
- CxImage的使用及基本用法
基本定义:CxImage类库是一个优秀的图像操作类库.它可以快捷地存取.显示.转换各种图像. 下载地址:http://www.codeproject.com/KB/graphics/cximage.a ...
- [poj 2185] Milking Grid 解题报告(KMP+最小循环节)
题目链接:http://poj.org/problem?id=2185 题目: Description Every morning when they are milked, the Farmer J ...
- solarwind之安装
1. 安装组件 2. 安装组件sql 3. 安装 4. 接受协议 5. 安装路径 6. 安装状态 7. 继续 8. 激活 9. 完成安装
- Eclipse使用struts2开发web应用快速搭建
eclipse 下载javaEE版,这里用4.5(Mars). Tomcat8解压,设置好JAVA_HOME环境变量. 下载struts2官网上的lib包,struts-2.3.24-lib.zip, ...
- 找出 alter system kill session ‘sid,serial#’ kill 掉的数据库会话对应进程
当我们使用alter system kill session ‘sid,serial#’ 在数据库中kill掉某个会话的时候,如果你观察仔细会发现v$session.paddr发生了改变,从而是的不能 ...
- SpringCloud学习笔记(15)----Spring Cloud Netflix之Hystrix Dashboard的使用
1. 引入依赖 在前面几节中的消费者中添加pom依赖. <dependency> <groupId>org.springframework.cloud</groupId& ...
- NodeJS学习笔记 (6)网络服务-http-res(ok)
原文:https://github.com/chyingp/nodejs-learning-guide 自己敲代码: 概览 http模块四剑客之一的res,应该都不陌生了.一个web服务程序,接受到来 ...
- 快速沃尔什变换(FWT)笔记
开头Orz hy,Orz yrx 部分转载自hy的博客 快速沃尔什变换,可以快速计算两个多项式的位运算卷积(即and,or和xor) 问题模型如下: 给出两个多项式$A(x)$,$B(x)$,求$C( ...
- C语言的常用printf打印占位符%d, %u, %f, %s, %c, %o, %x
占位符含义及用法 代码: #include <stdio.h> int main(int argc, char const *argv[]) { , b = -; // 默认10进制赋值 ...