【LeetCode】6 - ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)
P A H N
A P L S I I G
Y I R
And then read line by line: "PAHNAPLSIIGYIR"
Write the code that will take a string and make this conversion given a number of rows:
string convert(string text, int nRows);
convert("PAYPALISHIRING", 3) should return "PAHNAPLSIIGYIR".
Solution:原来是说:
class Solution {
public:
string convert(string s, int nRows) {
if(nRows==)return s;
vector<vector<char>> vec(nRows, vector<char>());
int index=-;
int tag=;
for(int i=;i<s.size();i++){
index += tag;
vec[index].push_back(s[i]);
if(index==nRows-)tag=-;
else{
if(index==)tag=;
}
}
string ret;
for(int i=;i<nRows;i++){
for(int j=;j<vec[i].size();j++){
ret+=vec[i][j];
}
}
return ret;
}
};
【LeetCode】6 - ZigZag Conversion的更多相关文章
- 【LeetCode】6. ZigZag Conversion Z 字形变换
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:字形变换,ZigZag,题解,Leetcode, 力扣,P ...
- 【LeetCode】006. ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...
- 【LeetCode】6. ZigZag Conversion 锯齿形转换
题目: 思路: 以图为例:s={'A','B','C','D','E','F','G','H'.....} 1.先不考虑中间元素F.G.H.N...,每一行前后元素在数组中对应下标相差size=2*n ...
- 【一天一道LeetCode】#6 ZigZag Conversion
一天一道LeetCode系列 (一)题目 The string "PAYPALISHIRING" is written in a zigzag pattern on a given ...
- 【LeetCode】281. Zigzag Iterator 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 deque 日期 题目地址:https://leetc ...
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- 【Leetcode】Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...
- 53. Maximum Subarray【leetcode】
53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...
- 27. Remove Element【leetcode】
27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...
随机推荐
- 页面关键词Meta Keywords和描述Description的优化作用
前几日有两三个童鞋们问我为什么文章目录页面没有设置关键词,我原先还以为什么关键词,后来才明白是问我为什么不添加Meta Keywords.关于这个问题我直接回应他们说目录页面Meta Keywords ...
- RAID
RAID(is short for redundant arrays of independent disks) 独立/廉价磁盘冗余阵列.基本思想:把多个相对便宜的硬盘组合起来,成为一个硬盘阵列组,使 ...
- Oracle在linux下的开机自启动(详细)转
linux下系统开机oracle自启动(方法一) ---加载为服务自启动.停止一.dbstart 及 dbshut 1. 修改Oracle系统配置文件:/etc/oratab,只有这样,Ora ...
- 计算机IT求职学习List
1. 算法相关 1.1 <编程珠玑> 1.2 <编程之美> 这两本是最经典的了,这里面注重的是解决问题的思路,看的时候里面的问题要认真思考再参考解答.下面两本是对具体的面试题做 ...
- android学习系列:jercy——AI3 的博客
[android学习之十七]——特色功能2:桌面组件(快捷方式,实时文件夹) 二.桌面组件 1.快捷方式 Android手机上得快捷方式的意思可以以我们实际PC机器上程序的快捷方式来理解.而andro ...
- 【笨嘴拙舌WINDOWS】SetCapture和ReleaseCapture
光电鼠标器是通过红外线或激光检测鼠标器的位移,将位移信号转换为电脉冲信号,再通过程序的处理和转换来控制屏幕上的光标箭头的移动的一种硬件设备. 换句话说,鼠标无时无刻不在监视着人类的活动,当人类用意识去 ...
- Spring MVC文件下载
方案一: // 文件下载 @RequestMapping(value = "/downloadFile") public ResponseEntity<byte[]> ...
- 【第三篇】说说javascript处理时间戳
在做datagrid的时候,从数据库读出来的数据是/Date(1437705873240)/大概是这种形式,这个就是时间戳 我们需要把/Data和/去掉,才可以转成我们要的格式. 上代码 { fiel ...
- php扩展编译(以memcached为例)
1)到 https://pecl.php.net/ 上搜索并下载(wget)你需要的扩展的源码包 2)解压并切换进入扩展包的目录 3)使用phpize工具自动生成 configure 4)config ...
- How to begin with the webpage making
1.网页制作三剑客必须要会使用.(dreamweaver /fireworks/flash)2.学习些最基层的html语言的知识,3.在学习一些基本的html标签(要多加练习哦)4.先试着用表格进行 ...