leetCode刷题(将字符串转成W形状的字符串再以Z形字符串输出)
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".
/**
* @param {string} s
* @param {number} numRows
* @return {string}
*/
var convert = function(s, numRows) {
var y=0;
var storeArr=[];
if(numRows==1){
return s;
}
for(var i=0;i<s.length;i++){
storeArr[y]=(storeArr[y]||"")+""+s[i];
y==0?(flag=true):"";
y==(numRows-1)?(flag=false):"";
flag?y++:y--;
}
return storeArr.join("");
};
leetCode刷题(将字符串转成W形状的字符串再以Z形字符串输出)的更多相关文章
- C#LeetCode刷题之#709-转换成小写字母(To Lower Case)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3965 访问. 实现函数 ToLowerCase(),该函数接收一 ...
- C#LeetCode刷题-字符串
字符串篇 # 题名 刷题 通过率 难度 3 无重复字符的最长子串 24.6% 中等 5 最长回文子串 22.4% 中等 6 Z字形变换 35.8% 中等 8 字符串转整数 (atoi) ...
- C#LeetCode刷题-数学
数学篇 # 题名 刷题 通过率 难度 2 两数相加 29.0% 中等 7 反转整数 C#LeetCode刷题之#7-反转整数(Reverse Integer) 28.6% 简单 8 字符串转整数 ...
- LeetCode刷题指南(字符串)
作者:CYC2018 文章链接:https://github.com/CyC2018/CS-Notes/blob/master/docs/notes/Leetcode+%E9%A2%98%E8%A7% ...
- C#LeetCode刷题之#205-同构字符串(Isomorphic Strings)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3770 访问. 给定两个字符串 s 和 t,判断它们是否是同构的. ...
- LeetCode刷题总结-树篇(中)
本篇接着<LeetCode刷题总结-树篇(上)>,讲解有关树的类型相关考点的习题,本期共收录17道题,1道简单题,10道中等题,6道困难题. 在LeetCode题库中,考察到的不同种类的树 ...
- C#LeetCode刷题-贪心算法
贪心算法篇 # 题名 刷题 通过率 难度 44 通配符匹配 17.8% 困难 45 跳跃游戏 II 25.5% 困难 55 跳跃游戏 30.6% 中等 122 买卖股票的最佳时机 II C ...
- C#LeetCode刷题-双指针
双指针篇 # 题名 刷题 通过率 难度 3 无重复字符的最长子串 24.5% 中等 11 盛最多水的容器 43.5% 中等 15 三数之和 16.1% 中等 16 最接近的三数之和 3 ...
- LeetCode刷题的一点个人建议和心得
目录 1. 为什么我们要刷LeetCode? 2. LeetCode的现状和问题 3. 本文的初衷 4. LeetCode刷题建议 4.1入门数据结构,打基础阶段 4.2 建立 ...
随机推荐
- 理解WebKit和Chromium: 硬件加速之RenderLayer树到合成树
转载请注明原文地址:http://blog.csdn.net/milado_nju ## 概述 在前面的章节中,笔者介绍了WebKit渲染引擎是如何有HTML网页构建DOM树.RenderObject ...
- Linux Shell 命令--tr
tr 用来从标准输入中通过替换或删除操作进行字符转换 -c或--complerment 取代所有不属于第一字符集的字符. -d ...
- [转].NET程序破解仅需三步
近期开发公司商城,为了简化开发用了V5Shop网店程序.本来预计一个月完工,哪知道出现一堆问题大大增加了我的工作量(早知道还不如全部自己写了). 破V5Shop真不地道,说是免费的,结果程序一大堆问题 ...
- 【一天一道LeetCode】#35. Search Insert Position
一天一道LeetCode系列 (一)题目 Given a sorted array and a target value, return the index if the target is foun ...
- Leetcode_121_Best Time to Buy and Sell Stock
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/43024967 Say you have an array ...
- Unity3D学习笔记(三)Unity的C#基础
在C#脚本中,必须显式的继承MonoBehaviour类需要注意的是,在创建C#脚本时,脚本名应尽量符合C#命名规则,以字母或下划线开头,因为类名的默认跟随脚本名.C#声明变量的方式和C++和Java ...
- 【一天一道LeetCode】#13. Roman to Integer
一天一道LeetCode系列 (一)题目 Given a roman numeral, convert it to an integer. Input is guaranteed to be with ...
- Erlang Rebar 使用指南之三:Rebar和OTP程序约定和命令
Erlang Rebar 使用指南之三:Rebar和OTP程序约定和命令 全文目录: https://github.com/rebar/rebar/wiki 本章位置: https://github. ...
- android的左右侧滑菜单实现
最近看了很多app应用都采用的是左右侧滑,比如网易新闻.凡客等 这里也试着写一下侧滑 首先看一下效果 然后给出xml布局代码 <RelativeLayout xmlns:android=&quo ...
- 那些年Android开发中遇到的坑
使用静态变量来缓存数据时,不管是在Application类还是其他类,都要注意因应用重建而引发的问题. 使用DecorView作为PopupWindow的anchorView时,在华为P7中它是显示在 ...